diff Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs @ 225:f23ee59ef1bd

Otros ponentes
author nelopauselli
date Mon, 26 Sep 2011 08:47:01 -0300
parents 5346c0500594
children c61954d24c8c
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs	Sun Sep 25 01:40:18 2011 -0300
+++ b/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs	Mon Sep 26 08:47:01 2011 -0300
@@ -1,4 +1,4 @@
-using System;
+using System.Reflection;
 using AltNetHispano.Agendas.Domain;
 using ConfOrm;
 using ConfOrm.NH;
@@ -34,7 +34,10 @@
 			orm.TablePerClass<Evento>();
 
 			orm.Complex<Evento>(e => e.Estado);
-
+			
+			orm.Bag<Evento>(e=>e.OtrosPonentes);
+			orm.ManyToMany<Evento, Persona>();
+			
 			orm.TablePerClass<Track>();
 			orm.TablePerClass<TrackLog>();
 			orm.TablePerClass<Cuenta>();
@@ -48,6 +51,7 @@
 			orm.Bag<Persona>(p => p.Roles);
 
 			var mapper = new Mapper(orm);
+			ColumnsNamingPatterns(mapper);
 
 			mapper.Customize<Persona>(a => a.Property(p => p.Nombre, m => m.Unique(true)));
 			mapper.Customize<Persona>(a => a.Property(p => p.Twitter, m => m.Unique(true)));
@@ -59,13 +63,25 @@
 					m => m.Element(em => em.Column("Rol"))));
 
 			mapper.Customize<Evento>(a => a.Property(p => p.Titulo, m => m.Unique(true)));
-			
-			mapper.AddPropertyPattern(p => p.DeclaringType == typeof(Evento) && p.Name == "Estado", a => a.Type<EventoStateType>());
+			mapper.Customize<Evento>(e=>e.Property(p=>p.Estado, a=>a.Type<EventoStateType>()) );
 
 			return mapper.CompileMappingFor(typeof(Evento).Assembly.GetTypes());
 
 		}
 
+		private static void ColumnsNamingPatterns(Mapper mapper)
+		{
+			//mapper.AddPoidPattern(mi => IsMemberOfClassOfAgendas(mi) && mi.Name == "Id",
+			//(mi, idm) => idm.Column(mi.ReflectedType.Name + "Id"));
+			//mapper.AddCollectionPattern(IsMemberOfClassOfAgendas, (mi, cm) => cm.Key(km => km.Column(mi.DeclaringType.Name + "Id")));
+			//mapper.AddManyToOnePattern(IsMemberOfClassOfAgendas, (mi, idm) => idm.Column(mi.GetPropertyOrFieldType().Name + "Id"));
+		}
+
+		private static bool IsMemberOfClassOfAgendas(MemberInfo mi)
+		{
+			return mi.ReflectedType.Assembly == typeof(Evento).Assembly;
+		}
+
 		public static ISessionFactory GetSessionFactory()
 		{
 			if (_sessionfactory == null)