Domain:
class Category
string Name
class Product
IDictionary<string, Product> Parents
Tables:
Categories (ID, Name)
Products (ID)
ProductParents (ID, ParentID, ChildID, CategoryID)
The questions: I need to get list of parent products. Is it possible to map parent products to dictionary so that I can do:
product.Parents[“CategoryName”]
and it will give me a list of parent products for the given category.
Or maybe
product.Parents[Category("CategoryName")]
if I use
IDictionary<Category, Product> Parents
Or how do I do this? Maybe a method like product.GetParentProducts(string category) instead of properties? I’d rather use dictionary, though.
Notice that I don’t really want to introduce ProductMapping class.
This is possible with NHibernate; what you’re looking for is called a ternary association.
This is currently not available in Fluent NHibernate, but I’m working to add it. However, it probably won’t be available for some time yet, due to the “replumbing” going on in FNH. Your best bet might be to use a standard HBM file for this mapping.
If you want to investigate further into doing it in FNH (note: you’ll have to maintain your own local copy of the library), you can see what I’ve done at github.