开发者

How to map composite primary key to foreign in fluent 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's a one-to-many relation between A and B. I can't simply 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);
    }
}

It will fail with the following exception:

Foreign key (FKE7804EB3DA7EBD4B:B [FOO]))开发者_如何学Go must have same number of columns as the referenced primary key (A [FOO, CLIENT])

Is it possible to map this correctly with fluent nhibernate?


Found the Solution:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜