Friday, April 15, 2011

NHibernate ManyToMany relationship that includes all of one side of the relationship

Given this db schema (it was handed down to me):


I'd like suggestions on how to both model this and map it using fluent-nhibernate.

The only thing I can come up with is a very active record style of modeling (a class for each table and the obvious associations).

Ignoring the db for a second though, I think I want every facility to always have a list of all of the compliance flags. This way I can ask the facility what the compliance date for flag "XX" is.

Any help would be appreciated even it's only a slight nudge in the right direction.

Thanks, Rob

From stackoverflow
  • I think the best way is what you've already suggested, to map each table as an entity. If you didn't have additional data in the join table you wouldn't need to, but as you do they should really be separate entities.

    You'd have three entities. Facility and Compliance would have a HasMany to Facil_Compliance. You'd also have a References from Facil_Compliance back to each table. You may optionally remove a direction from this relationship if you only ever need to go one way.


Post a Comment