# HG changeset patch
# User nelopauselli
# Date 1311967853 10800
# Node ID 3639803112c69d9778c555bfd8cb3d78f43ba218
# Parent 18e5a78186e424701a275d1d726c965cc2f5f1a2
Refactoring de la relación entre Evento y Estado
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/Evento.cs
--- a/Agendas/trunk/src/Agendas.Domain/Evento.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,7 +1,5 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using AltNetHispano.Agendas.Domain.Exceptions;
namespace AltNetHispano.Agendas.Domain
{
@@ -56,63 +54,20 @@
get { return _tracks; }
}
+ private EventoState _estado;
+
///
/// Estado del evento en formato string (para persistencia a DB)
///
- public virtual string Estado
+ public virtual EventoState Estado
{
- get
- {
- if (_eventoState != null)
- return _eventoState.GetDescripcion();
-
- return string.Empty;
- }
- set
- {
- if (value != Estado)
- {
- if (EventoPropuestoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoPropuestoState.GetInstance();
- else if (EventoAgendadoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoAgendadoState.GetInstance();
- else if (EventoConfirmadoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoConfirmadoState.GetInstance();
- else if (EventoPublicadoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoPublicadoState.GetInstance();
- else if (EventoCanceladoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoCanceladoState.GetInstance();
- else if (EventoDescartadoState.GetInstance().GetDescripcion().Equals(value))
- _eventoState = EventoDescartadoState.GetInstance();
- else
- throw new InvalidStateException(value);
- }
- }
+ get { return _estado ?? EventoNullState.GetInstance(); }
+ set { _estado = value; }
}
- private EventoState _eventoState;
+ //private EventoState _eventoState;
private IList _patrocinadores;
- ///
- /// Obtiene una instancia de la clase que representa el estado del evento
- ///
- public virtual EventoState GetEstado()
- {
- if (_eventoState == null)
- SetEstado(EventoNullState.GetInstance());
-
- return _eventoState;
- }
-
- ///
- /// Asigna la instancia de la clase que representa el estado del evento
- ///
- /// Instancia que representa el estado
- public virtual void SetEstado(EventoState eventoState)
- {
- _eventoState = eventoState;
- }
-
public virtual TipoEvento Tipo { get; private set; }
public virtual IEnumerable Patrocinadores
@@ -149,7 +104,7 @@
public static Evento Proponer(string titulo, Persona persona, string urlInvitacion, TipoEvento tipo)
{
var evento = new Evento { Titulo = titulo, Ponente = persona, UrlInvitacion = urlInvitacion, Tipo = tipo };
- evento.GetEstado().Promover(evento, Accion.Proponer);
+ evento.Estado.Promover(evento, Accion.Proponer);
return evento;
}
@@ -182,7 +137,7 @@
Ponente = persona;
Fecha = fecha;
UrlInvitacion = urlInvitacion;
- this.GetEstado().Promover(this, Accion.Agendar);
+ this.Estado.Promover(this, Accion.Agendar);
}
public virtual void Actualizar(Persona persona, DateTime? fecha, string urlInvitacion)
@@ -202,34 +157,34 @@
public virtual void Confirmar()
{
- this.GetEstado().Promover(this, Accion.Confirmar);
+ this.Estado.Promover(this, Accion.Confirmar);
}
public virtual void Publicar(short numeroOrden, string urlWiki)
{
this.NumeroOrden = numeroOrden;
this.UrlWiki = urlWiki;
- this.GetEstado().Promover(this, Accion.Publicar);
+ this.Estado.Promover(this, Accion.Publicar);
}
public virtual void Cancelar()
{
- GetEstado().Promover(this, Accion.Cancelar);
+ Estado.Promover(this, Accion.Cancelar);
}
public virtual void Descartar()
{
- GetEstado().Promover(this, Accion.Descartar);
+ Estado.Promover(this, Accion.Descartar);
}
public virtual void ReProponer()
{
- GetEstado().Promover(this, Accion.ReProponer);
+ Estado.Promover(this, Accion.ReProponer);
}
public virtual void ReAgendar()
{
- GetEstado().Promover(this, Accion.ReAgendar);
+ Estado.Promover(this, Accion.ReAgendar);
}
#endregion
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoAgendadoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoAgendadoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoAgendadoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,47 +1,44 @@
-using System;
-using AltNetHispano.Agendas.Domain.Exceptions;
+using AltNetHispano.Agendas.Domain.Exceptions;
namespace AltNetHispano.Agendas.Domain
{
- public class EventoAgendadoState : EventoState
- {
- private EventoAgendadoState()
- {
- }
+ public class EventoAgendadoState : EventoState
+ {
+ protected EventoAgendadoState()
+ {
+ }
- private static readonly EventoState _instance = new EventoAgendadoState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "Agendado";
+ private static readonly EventoState _instance = new EventoAgendadoState();
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- switch (accion)
- {
- case Accion.Confirmar:
- evento.SetEstado(EventoConfirmadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Confirmar));
- break;
- case Accion.Cancelar:
- evento.SetEstado(EventoCanceladoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Cancelar));
- break;
- default:
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ switch (accion)
+ {
+ case Accion.Confirmar:
+ evento.Estado=EventoConfirmadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Confirmar));
+ break;
+ case Accion.Cancelar:
+ evento.Estado = EventoCanceladoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Cancelar));
+ break;
+ default:
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Agendado"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return accion == Accion.Confirmar || accion == Accion.Cancelar;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return accion == Accion.Confirmar || accion == Accion.Cancelar;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoCanceladoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoCanceladoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoCanceladoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,51 +1,50 @@
-using AltNetHispano.Agendas.Domain.Exceptions;
+using System;
+using AltNetHispano.Agendas.Domain.Exceptions;
namespace AltNetHispano.Agendas.Domain
{
- public class EventoCanceladoState : EventoState
- {
- private EventoCanceladoState()
- {
- }
+ public class EventoCanceladoState : EventoState
+ {
+ protected EventoCanceladoState()
+ {
+ }
- private static readonly EventoState _instance = new EventoCanceladoState();
+ private static readonly EventoState _instance = new EventoCanceladoState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "Cancelado";
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- switch (accion)
- {
- case Accion.Descartar:
- evento.SetEstado(EventoDescartadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Descartar));
- break;
- case Accion.ReAgendar:
- evento.SetEstado(EventoAgendadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.ReAgendar));
- break;
- case Accion.ReProponer:
- evento.SetEstado(EventoPropuestoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.ReProponer));
- break;
- default:
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ switch (accion)
+ {
+ case Accion.Descartar:
+ evento.Estado = EventoDescartadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Descartar));
+ break;
+ case Accion.ReAgendar:
+ evento.Estado = EventoAgendadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.ReAgendar));
+ break;
+ case Accion.ReProponer:
+ evento.Estado = EventoPropuestoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.ReProponer));
+ break;
+ default:
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Cancelado"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return accion == Accion.Descartar || accion == Accion.ReAgendar || accion == Accion.ReProponer;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return accion == Accion.Descartar || accion == Accion.ReAgendar || accion == Accion.ReProponer;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoConfirmadoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoConfirmadoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoConfirmadoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -3,41 +3,39 @@
namespace AltNetHispano.Agendas.Domain
{
- public class EventoConfirmadoState : EventoState
- {
- private EventoConfirmadoState()
- {
- }
+ public class EventoConfirmadoState : EventoState
+ {
+ protected EventoConfirmadoState()
+ {
+ }
- private static readonly EventoState _instance = new EventoConfirmadoState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "Confirmado";
+ private static readonly EventoState _instance = new EventoConfirmadoState();
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- switch (accion)
- {
- case Accion.Publicar:
- evento.SetEstado(EventoPublicadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Publicar));
- break;
- default:
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ switch (accion)
+ {
+ case Accion.Publicar:
+ evento.Estado = EventoPublicadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Publicar));
+ break;
+ default:
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Confirmado"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return accion == Accion.Publicar;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return accion == Accion.Publicar;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoDescartadoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoDescartadoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoDescartadoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,10 +1,11 @@
-using AltNetHispano.Agendas.Domain.Exceptions;
+using System;
+using AltNetHispano.Agendas.Domain.Exceptions;
namespace AltNetHispano.Agendas.Domain
{
public class EventoDescartadoState : EventoState
{
- private EventoDescartadoState()
+ protected EventoDescartadoState()
{
}
@@ -15,19 +16,17 @@
return _instance;
}
- private const string Descripcion = "Descartado";
-
public override void Promover(Evento evento, Accion accion)
{
throw new AccionNoSoportadaException(this.GetType(), accion);
}
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Descartado"; }
+ }
- public override bool PuedePromover(Accion accion)
+ public override bool PuedePromover(Accion accion)
{
return false;
}
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoNullState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoNullState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoNullState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -3,45 +3,43 @@
namespace AltNetHispano.Agendas.Domain
{
- public class EventoNullState : EventoState
- {
- private EventoNullState()
- {
- }
+ public class EventoNullState : EventoState
+ {
+ protected EventoNullState()
+ {
+ }
- private static readonly EventoState _instance = new EventoNullState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "NullState";
+ private static readonly EventoState _instance = new EventoNullState();
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- switch (accion)
- {
- case Accion.Proponer:
- evento.SetEstado(EventoPropuestoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Proponer));
- break;
- case Accion.Agendar:
- evento.SetEstado(EventoAgendadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Agendar));
- break;
- default:
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ switch (accion)
+ {
+ case Accion.Proponer:
+ evento.Estado = EventoPropuestoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Proponer));
+ break;
+ case Accion.Agendar:
+ evento.Estado = EventoAgendadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Agendar));
+ break;
+ default:
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "NullState"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return accion == Accion.Proponer || accion == Accion.Agendar;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return accion == Accion.Proponer || accion == Accion.Agendar;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoPropuestoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoPropuestoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoPropuestoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -3,45 +3,43 @@
namespace AltNetHispano.Agendas.Domain
{
- public class EventoPropuestoState : EventoState
- {
- private EventoPropuestoState()
- {
- }
+ public class EventoPropuestoState : EventoState
+ {
+ protected EventoPropuestoState()
+ {
+ }
- private static readonly EventoState _instance = new EventoPropuestoState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "Propuesto";
+ private static readonly EventoState _instance = new EventoPropuestoState();
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- switch (accion)
- {
- case Accion.Agendar:
- evento.SetEstado(EventoAgendadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Agendar));
- break;
- case Accion.Descartar:
- evento.SetEstado(EventoDescartadoState.GetInstance());
- evento.AddTrack(new Track(evento, Accion.Descartar));
- break;
- default:
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ switch (accion)
+ {
+ case Accion.Agendar:
+ evento.Estado = EventoAgendadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Agendar));
+ break;
+ case Accion.Descartar:
+ evento.Estado = EventoDescartadoState.GetInstance();
+ evento.AddTrack(new Track(evento, Accion.Descartar));
+ break;
+ default:
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Propuesto"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return accion == Accion.Agendar || accion == Accion.Descartar;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return accion == Accion.Agendar || accion == Accion.Descartar;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoPublicadoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoPublicadoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoPublicadoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -3,33 +3,31 @@
namespace AltNetHispano.Agendas.Domain
{
- public class EventoPublicadoState : EventoState
- {
- private EventoPublicadoState()
- {
- }
+ public class EventoPublicadoState : EventoState
+ {
+ protected EventoPublicadoState()
+ {
+ }
- private static readonly EventoState _instance = new EventoPublicadoState();
- public static EventoState GetInstance()
- {
- return _instance;
- }
-
- private const string Descripcion = "Publicado";
+ private static readonly EventoState _instance = new EventoPublicadoState();
+ public static EventoState GetInstance()
+ {
+ return _instance;
+ }
- public override void Promover(Evento evento, Accion accion)
- {
- throw new AccionNoSoportadaException(this.GetType(), accion);
- }
+ public override void Promover(Evento evento, Accion accion)
+ {
+ throw new AccionNoSoportadaException(this.GetType(), accion);
+ }
- public override string GetDescripcion()
- {
- return Descripcion;
- }
+ public override string Descripcion
+ {
+ get { return "Publicado"; }
+ }
- public override bool PuedePromover(Accion accion)
- {
- return false;
- }
- }
+ public override bool PuedePromover(Accion accion)
+ {
+ return false;
+ }
+ }
}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.Domain/EventoState.cs
--- a/Agendas/trunk/src/Agendas.Domain/EventoState.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/EventoState.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,16 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Collections.Generic;
namespace AltNetHispano.Agendas.Domain
{
- public abstract class EventoState
- {
- public abstract void Promover(Evento evento, Accion accion);
+ public abstract class EventoState
+ {
+ public abstract void Promover(Evento evento, Accion accion);
- public abstract string GetDescripcion();
+ public abstract string Descripcion { get; }
- public abstract bool PuedePromover(Accion accion);
- }
-}
+ public abstract bool PuedePromover(Accion accion);
+ }
+}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.NHibernate/Agendas.NHibernate.csproj
--- a/Agendas/trunk/src/Agendas.NHibernate/Agendas.NHibernate.csproj Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.NHibernate/Agendas.NHibernate.csproj Fri Jul 29 16:30:53 2011 -0300
@@ -53,6 +53,8 @@
+
+
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.NHibernate/EventoStateType.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.NHibernate/EventoStateType.cs Fri Jul 29 16:30:53 2011 -0300
@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+using AltNetHispano.Agendas.Domain;
+using NHibernate.SqlTypes;
+
+namespace Agendas.NHibernate
+{
+ public class EventoStateType : GenericWellKnownInstanceType
+ {
+ public static IEnumerable All
+ {
+ get
+ {
+ return new[]
+ {
+ EventoNullState.GetInstance(), EventoPropuestoState.GetInstance(), EventoAgendadoState.GetInstance(),
+ EventoConfirmadoState.GetInstance(), EventoPublicadoState.GetInstance(), EventoCanceladoState.GetInstance(),
+ EventoDescartadoState.GetInstance()
+ };
+ }
+ }
+
+ public EventoStateType()
+ : base(All, (state, id) => state.Descripcion == id, state => state.Descripcion)
+ {
+ }
+
+ public override SqlType[] SqlTypes
+ {
+ get { return new[] {SqlTypeFactory.GetString(25)}; }
+ }
+ }
+}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.NHibernate/GenericWellKnownInstanceType.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.NHibernate/GenericWellKnownInstanceType.cs Fri Jul 29 16:30:53 2011 -0300
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using NHibernate.SqlTypes;
+using NHibernate.UserTypes;
+
+namespace Agendas.NHibernate
+{
+ [Serializable]
+ public abstract class GenericWellKnownInstanceType : IUserType where T : class
+ {
+ //private static readonly SqlType[] ReturnSqlTypes = { SqlTypeFactory.Int32 };
+ private Func findPredicate;
+ private Func idGetter;
+ private IEnumerable repository;
+
+ ///
+ /// Base constructor
+ ///
+ /// The collection that represent a in-memory repository.
+ /// The predicate an instance by the persisted value.
+ /// The getter of the persisted value.
+ protected GenericWellKnownInstanceType(IEnumerable repository, Func findPredicate, Func idGetter)
+ {
+ this.repository = repository;
+ this.findPredicate = findPredicate;
+ this.idGetter = idGetter;
+ }
+
+ //public SqlType[] SqlTypes
+ //{
+ // get { return ReturnSqlTypes; }
+ //}
+
+ public Type ReturnedType
+ {
+ get { return typeof(T); }
+ }
+
+ public bool IsMutable
+ {
+ get { return false; }
+ }
+
+ public new bool Equals(object x, object y)
+ {
+ if (ReferenceEquals(x, y))
+ {
+ return true;
+ }
+ if (ReferenceEquals(null, x) || ReferenceEquals(null, y))
+ {
+ return false;
+ }
+
+ return x.Equals(y);
+ }
+
+ public int GetHashCode(object x)
+ {
+ return (x == null) ? 0 : x.GetHashCode();
+ }
+
+ public object NullSafeGet(IDataReader rs, string[] names, object owner)
+ {
+ int index0 = rs.GetOrdinal(names[0]);
+ if (rs.IsDBNull(index0))
+ {
+ return null;
+ }
+
+ var value = (TId)rs.GetValue(index0);
+ return repository.FirstOrDefault(x => findPredicate(x, value));
+ }
+
+ public void NullSafeSet(IDbCommand cmd, object value, int index)
+ {
+ if (value == null)
+ {
+ ((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
+ }
+ else
+ {
+ ((IDbDataParameter)cmd.Parameters[index]).Value = idGetter((T)value);
+ }
+ }
+
+ public object DeepCopy(object value)
+ {
+ return value;
+ }
+
+ public object Replace(object original, object target, object owner)
+ {
+ return original;
+ }
+
+ public object Assemble(object cached, object owner)
+ {
+ return cached;
+ }
+
+ public object Disassemble(object value)
+ {
+ return value;
+ }
+
+ ///
+ /// The SQL types for the columns mapped by this type.
+ ///
+ public abstract SqlType[] SqlTypes { get; }
+ }
+}
\ No newline at end of file
diff -r 18e5a78186e4 -r 3639803112c6 Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs
--- a/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs Thu Jul 28 10:16:09 2011 -0300
+++ b/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs Fri Jul 29 16:30:53 2011 -0300
@@ -1,9 +1,14 @@
-using AltNetHispano.Agendas.Domain;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using AltNetHispano.Agendas.Domain;
using ConfOrm;
using ConfOrm.NH;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
+using NHibernate.Type;
+using NHibernate.UserTypes;
namespace Agendas.NHibernate
{
@@ -19,6 +24,9 @@
var orm = new ObjectRelationalMapper();
orm.TablePerClass();
orm.TablePerClass();
+
+ orm.Complex(e => e.Estado);
+
orm.TablePerClass