How to match a composite primary key with a foreign language in anhydrous nhibernate?

I have the following tables:

table A:

 FOO (PK) | CLIENT (PK)

table B:

 BAR (PK) | CLIENT (PK/FK) | FOO (FK)

PK → primary key

FK → foreign key

There is a one-to-many relationship between A and B. I can't just do this:

class AMap
{
    public AMap()
    {
        CompositeId().KeyReference(a => a.FOO)
                     .KeyReference(a => a.CLIENT);
        HasMany(a => a.B);
    }
}


class BMap
{
    public BMap()
    {
        CompositeId().KeyReference(a => a.BAR)
                     .KeyReference(a => a.CLIENT);
        References(a => a.A);
    }
}

This will crash with the following exception:

The foreign key (FKE7804EB3DA7EBD4B: B [FOO])) must have the same number of columns as the primary key (A [FOO, CLIENT])

Is it possible to display this correctly with free nhibernate?

+3
source share
1 answer

Found a solution:

HasMany(a => a.B).KeyColumns.Add("FOO", "CLIENT").Cascade.All(); 
+6
source

Source: https://habr.com/ru/post/1780665/


All Articles