How can you map and work with a junction table in fluent nhibernate?

364 views Asked by At

I have the classic scenario with 2 tables and a junction table. Let's say, Locations, Prices and LocationXPrices.

LocationXPrices contains only the id's of Locations and Prices so that we know how they relate.

The best approach we came to is like this: - map Locations as many to many to Prices - map Prices as many to many to Locations - no specific mapping and no .NET object for LocationsXPrices.

The junction will be created when Locations will be read. Insert will be done together with Location.

Is this the best practice to work with this scenario ? Can anyone provide a better solution ? It doesn't' feel that natural to me.

Thank you, Mosu.

1

There are 1 answers

1
David M On BEST ANSWER

Yes, this is best practice where your junction table represents a pure weak entity like this, with no other information. The junction table is merely a necessary artifact of modelling this sort of situation in an RDBMS; NHibernate lets you hide it totally so you can work with a genuine many-many relationship rather than the RDBMS's enforced many-one-many.