Creating a convention to differentiate between HasMany and HasManyToMany collections

19 views
Skip to first unread message

Chris Marisic

unread,
Jan 15, 2010, 3:02:52 PM1/15/10
to Fluent NHibernate
Is it possible to create a convention that says if class is similar to

MyClassA
IList<SomeType> SomeTypesCollection {get;set;}

That would be equivalent to

Override<MyClassA>(a => a.HasManyToMany
(x=>x.SomeTypesCollection).Table
("SomeTypes"))

And a convention that would be like

AnotherClassB
IList<DifferentType> DifferentTypes {get;set;}

That would be equivalent to

Override<AnotherClassB>(a => a.HasManyToMany(x=>x.DifferentTypes))

I'm trying to implement one of the many Convention classes in
FluentNHibernate so I don't have

return AutoMap.AssemblyOf<NotifyRun>()
.Where(t => t.IsA<BusinessEntity>())
.IgnoreBase<BusinessEntity>()
.Conventions.AddFromAssemblyOf<NHibernateSessionManager>
()
.Override<MyClassA>(myClassA =>
myClassA .HasManyToMany
(x => x.SomeTypesCollection).Table("SomeTypes"))
.Override<AnotherClassB >(anotherClassB =>
anotherClassB .HasMany(x => x.DifferentTypes))
.Override<1MyClassA>(1myClassA =>
1myClassA .HasManyToMany(x => x.1SomeTypesCollection).Table
("1SomeTypes"))
.Override<2AnotherClassB >(2anotherClassB =>
2anotherClassB .HasMany(x => x.2DifferentTypes))
.Override<3MyClassA>(3myClassA =>
3myClassA .HasManyToMany(x => x.3SomeTypesCollection).Table
("3SomeTypes"))
.Override<4AnotherClassB >(4anotherClassB =>
4anotherClassB .HasMany(x => x.4DifferentTypes))
)
etc

Paul Batum

unread,
Jan 30, 2010, 11:07:38 PM1/30/10
to fluent-nhibernate
I find using separate classes for my mapping overrides makes them more manageable. 

As for removing the need for the overrides altogether, I'm not quite following. What are the rules for determining which associations are one-to-many and which associations are many-to-many?

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.




Reply all
Reply to author
Forward
0 new messages