NHibernate Shared Key Combinations

I have two tables with compound keys and a table of links between them:

  • AND

    • help (PK)
    • sharedkey (PK)
  • AT

    • rate (PK)
    • sharedkey (PK)
  • Communication

    • help
    • rate
    • sharedkey
    • Sortortr

So the inconvenient thing is the shared key, which is part of both FKs. Here's the first thing I tried (I use Fluent, but I would have the same problem with XML mappings):

mapping.HasManyToMany(x => x.Bees)
    .Table("Linking")
    .ParentKeyColumns.Add("aid", "sharedkey")
    .ChildKeyColumns.Add("bid", "sharedkey")
    .OrderBy("sortorder");

Which gives me a matching exception: "Duplicate column when matching for collection" because I inserted twice sharedkey. This makes sense because I did not say at NH that I really want to sharedkeybe the same in every direction.

Java- Hibernate formula , , NH, AFAIK, . , ?

:

  • , Fluent. XML .
  • , , - ,
+3
1

public AMap()
{
    CompositeId()
        .KeyProperty(x => x.Id, "aid")
        .KeyProperty(x => x.Name, "sharedkey");

    HasManyToMany(x => x.Bees)
        .Table("Linking")
        .ParentKeyColumns.Add("aid", "sharedkey")
        .ChildKeyColumn("bid").ChildPropertyRef("Id")
        .OrderBy("sortorder")
        ;
}

public BMap()
{
    CompositeId()
        .KeyProperty(x => x.Id, "bid")
        .KeyProperty(x => x.Name, "sharedkey");

    Map(x => x.Id, "bid")
        .Not.Insert();
}

B, ( sql):

SELECT l.bid FROM a LEFT JOIN linking l ON a.aid = l.aid AND a.sharedkey = l.sharedkey WHERE a.aid = ?

B .

+1

All Articles