NHibernate: Many-to-many relationship with field in the relationship table

若如初见. 提交于 2019-11-27 23:13:13

Make the relationship an entity:

class CarRelation
{
  Car Car {get; set; }
  RelationType Type {get; set;}
}

A pure many-to-many relation doesn't have any additional properties.

I think that you are missing an additional entity. You need to add an entity that expresses the customer's interest in the car. You will need to find the right name to fit your business domain, but here is my guess:

You have CUSTOMER table to store information about a specific customer. CUSTOMER has a one to many relationship to the CUSTOMERINTEREST table. CUSTOMERINTEREST stores information about the kinds of shopping activities the customer is engaged in (test drives, window shopping, etc.). CUSTOMERINTEREST has a many to one relationship with the CAR table. CAR stores information about specific automobiles in the store's inventory.

So, my best guess is that if the thing in the middle of your relationship needs more columns than just the two foreign keys then you don't really have a many to many relationship. You have two many to one relationships and you just haven't identified the thing in the middle yet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!