Many-to-many mapping with extra columns in join table

前端 未结 5 1029
慢半拍i
慢半拍i 2021-01-22 00:51

Here is the domain that I wish to have:

public class Person
{
    public int Id { get; set; }
    public IList AcquiredCertificates {          


        
相关标签:
5条回答
  • 2021-01-22 01:27

    Your implementation is exactly correct. Your join table includes the two key fields (making a composite primary key for the table) and the datetime field is superfluous to that. It is in fact an extra attribute on the join table and for that you need an entity.

    On a UML class diagram it would show up as an attribute on the join too.

    0 讨论(0)
  • 2021-01-22 01:33

    By design, NHibernate only supports the implicit many-to-many mapping if there is absolutely NOTHING other than the pair of FKs represented in the intermediate (middle) table that holds the many-to-many relationship.

    Some time ago, Billy McCafferty blogged about this exact 'issue' (not really an issue since its BY DESIGN)...

    http://devlicio.us/blogs/billy_mccafferty/archive/2008/07/11/when-to-use-many-to-one-s-vs-many-to-many-with-nhibernate.aspx

    0 讨论(0)
  • 2021-01-22 01:34

    I think you need 3, if you are ever going to get at the DateTime value.

    0 讨论(0)
  • 2021-01-22 01:40

    Re: your updated Q, you will need three mappings, one for each of the three entities that now participate in the pair of one-to-many relations.

    0 讨论(0)
  • 2021-01-22 01:41

    I would rename CertificatesAcquiredByPeople something
    like CertificatesAcquiredEvent (it implies that there is more than one key and a datetime)

    I agree it needs to be a seperate Entity as far as NHibernate is concerned.

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