Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
224:de6d206bd5c3 | 225:f23ee59ef1bd |
---|---|
1 using System; | 1 using System.Reflection; |
2 using AltNetHispano.Agendas.Domain; | 2 using AltNetHispano.Agendas.Domain; |
3 using ConfOrm; | 3 using ConfOrm; |
4 using ConfOrm.NH; | 4 using ConfOrm.NH; |
5 using NHibernate; | 5 using NHibernate; |
6 using NHibernate.Cfg; | 6 using NHibernate.Cfg; |
32 var orm = new ObjectRelationalMapper(); | 32 var orm = new ObjectRelationalMapper(); |
33 orm.TablePerClass<Persona>(); | 33 orm.TablePerClass<Persona>(); |
34 orm.TablePerClass<Evento>(); | 34 orm.TablePerClass<Evento>(); |
35 | 35 |
36 orm.Complex<Evento>(e => e.Estado); | 36 orm.Complex<Evento>(e => e.Estado); |
37 | 37 |
38 orm.Bag<Evento>(e=>e.OtrosPonentes); | |
39 orm.ManyToMany<Evento, Persona>(); | |
40 | |
38 orm.TablePerClass<Track>(); | 41 orm.TablePerClass<Track>(); |
39 orm.TablePerClass<TrackLog>(); | 42 orm.TablePerClass<TrackLog>(); |
40 orm.TablePerClass<Cuenta>(); | 43 orm.TablePerClass<Cuenta>(); |
41 //orm.TablePerClass<Patrocinador>(); | 44 //orm.TablePerClass<Patrocinador>(); |
42 | 45 |
46 orm.Cascade<Persona, Cuenta>(Cascade.All | Cascade.DeleteOrphans); | 49 orm.Cascade<Persona, Cuenta>(Cascade.All | Cascade.DeleteOrphans); |
47 | 50 |
48 orm.Bag<Persona>(p => p.Roles); | 51 orm.Bag<Persona>(p => p.Roles); |
49 | 52 |
50 var mapper = new Mapper(orm); | 53 var mapper = new Mapper(orm); |
54 ColumnsNamingPatterns(mapper); | |
51 | 55 |
52 mapper.Customize<Persona>(a => a.Property(p => p.Nombre, m => m.Unique(true))); | 56 mapper.Customize<Persona>(a => a.Property(p => p.Nombre, m => m.Unique(true))); |
53 mapper.Customize<Persona>(a => a.Property(p => p.Twitter, m => m.Unique(true))); | 57 mapper.Customize<Persona>(a => a.Property(p => p.Twitter, m => m.Unique(true))); |
54 | 58 |
55 mapper.Class<Persona>( | 59 mapper.Class<Persona>( |
57 p => p.Roles, | 61 p => p.Roles, |
58 cm => cm.Key(em => em.Column("Persona")), | 62 cm => cm.Key(em => em.Column("Persona")), |
59 m => m.Element(em => em.Column("Rol")))); | 63 m => m.Element(em => em.Column("Rol")))); |
60 | 64 |
61 mapper.Customize<Evento>(a => a.Property(p => p.Titulo, m => m.Unique(true))); | 65 mapper.Customize<Evento>(a => a.Property(p => p.Titulo, m => m.Unique(true))); |
62 | 66 mapper.Customize<Evento>(e=>e.Property(p=>p.Estado, a=>a.Type<EventoStateType>()) ); |
63 mapper.AddPropertyPattern(p => p.DeclaringType == typeof(Evento) && p.Name == "Estado", a => a.Type<EventoStateType>()); | |
64 | 67 |
65 return mapper.CompileMappingFor(typeof(Evento).Assembly.GetTypes()); | 68 return mapper.CompileMappingFor(typeof(Evento).Assembly.GetTypes()); |
66 | 69 |
70 } | |
71 | |
72 private static void ColumnsNamingPatterns(Mapper mapper) | |
73 { | |
74 //mapper.AddPoidPattern(mi => IsMemberOfClassOfAgendas(mi) && mi.Name == "Id", | |
75 //(mi, idm) => idm.Column(mi.ReflectedType.Name + "Id")); | |
76 //mapper.AddCollectionPattern(IsMemberOfClassOfAgendas, (mi, cm) => cm.Key(km => km.Column(mi.DeclaringType.Name + "Id"))); | |
77 //mapper.AddManyToOnePattern(IsMemberOfClassOfAgendas, (mi, idm) => idm.Column(mi.GetPropertyOrFieldType().Name + "Id")); | |
78 } | |
79 | |
80 private static bool IsMemberOfClassOfAgendas(MemberInfo mi) | |
81 { | |
82 return mi.ReflectedType.Assembly == typeof(Evento).Assembly; | |
67 } | 83 } |
68 | 84 |
69 public static ISessionFactory GetSessionFactory() | 85 public static ISessionFactory GetSessionFactory() |
70 { | 86 { |
71 if (_sessionfactory == null) | 87 if (_sessionfactory == null) |