NHibernate (free) and many, many mappings with additional metadata

I am trying to decide how to manage the next relationship

There are many products
in the store The product is in many stores The store knows how much of each product it has

In the database, I have 3 tables, Stores and Store Store products that have StoreId, ProductId and quantity.

How do I map this in nHibernate or fluently nHibernate?

+2


source to share


2 answers


[This answer is ORM generic and not FNH specific]

In the (very good) book NHibernate in Action (see section 6.3.2), the authors argue that it's almost never worth using multivalued matching, because you almost always find (possibly later) that you want to attach additional metadata to "link" between these two objects, and therefore you can also model this right to your own right (as you say, did in your question).



As you already figured out, you need to create a StoreProducts object and many-one and one-many to complete the association.

... only if you want to confirm that this is the "recommended" approach :-)

+1


source


You will need to render a third object, I don't think the built-in Many To Many function supports this. It would be great if someone could prove that I am wrong.



0


source







All Articles