2
votes

I am trying to work out how to manage the following relationships

A Store has many Products
A Product is in many Stores A Store knows how many of each Product it has

In the database I have 3 tables Stores, Products and a StoreProducts that has StoreId, ProductId and Quantity.

How would I map this in nHibernate or fluent nHibernate?

2
psst, re: your flag--your ips are completely different, so as a precaution can you please edit the account you want merged into this one to add "please merge my account into shaun" in the "about me" section, then re-flag asking for a merge. Thanks.user1228

2 Answers

1
votes

[This answer is general to ORM and not specific to FNH]

In the (very good) book NHibernate In Action (see Section 6.3.2) the authors express the opinion that it's almost never worthwile using a many-many mapping because you'll almost always discover (maybe later) that you want to attach extra meta-data to the 'link' between the two entities and so you may as well model this an an entitiy in it's own right (as you say have done in your question).

As you've discovered already, you need to create the StoreProducts entity and a many-one and a one-many to complete the association.

...just though you'd like to confirmation that this is a 'recommended' approach :-)

0
votes

Your going to have to map a 3rd entity, I don't think the built in Many To Many functionality supports that. Would be cool if someone proved me wrong though.