additional fields in NHibernate many-to-many relation tables

前端 未结 3 1124
轮回少年
轮回少年 2020-12-04 02:48

when i have a many-to.many relation with nhibernate and let nhibernate generate my db schema, it adds an aditional table that contains the primary keys of the related entiti

相关标签:
3条回答
  • 2020-12-04 03:12

    In this case, how would you build the in the mapping file for the new entity (that acts as the bridge between the two initial tables) ? In my case this link table has two foreign keys (int), one for each initial table, plus some other fields (startDate, endDate)

    The thing is, in my new entity, I do not have properties for these two foreign keys. I only have one property that is of the type of the entity the foreign key is pointing to.

    0 讨论(0)
  • 2020-12-04 03:16

    I don't think thats possible. If you are saying that the relation has some state than in essence it is an object in it's own right and should be treated (mapped) as such.

    0 讨论(0)
  • 2020-12-04 03:31

    Agree with Jasper. What you are modeling in that case is not a relation but an entity itself, with 1-N and N-1 relations to the other two entities.

    It is not that NHibernate cannot handle it, it is that you simply cannot model it.

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