How to map many-to-many in NHibernate correctly

added by notherdev
12/1/2011 5:13:07 AM

0 Kicks, 135 Views

Many-to-many relationships exist only at object model level - at database level it is only a concept implemented using two many-to-one relations with intermediate table. We can implement it the same way in our NHibernate-based object model, but we don't want User and Group to have collections of some UserInGroup objects that have no real object-oriented meaning. We do want User to have many Groups and Group to have many Users - as simple as it can be. Fortunately, this is quite common scenario and NHibernate can support it very well with respect to database-level constraints and good practices, but only when mapped and used with care.


0 comments