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

后端 未结 2 762
孤城傲影
孤城傲影 2020-12-06 07:50

I\'m scratching my head; I have a Car table and a Customer table that have a many-to-many relationship. In this relationship table I want to add a column that can tell me wh

相关标签:
2条回答
  • 2020-12-06 08:13

    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.

    0 讨论(0)
  • 2020-12-06 08:23

    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.

    0 讨论(0)
提交回复
热议问题