如何将复合主键映射到外部流利的nhibernate? [英] How to map composite primary key to foreign in fluent nhibernate?
本文介绍了如何将复合主键映射到外部流利的nhibernate?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下表格:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ F $($)客户(PK)
表B:
BAR(PK)|客户端(PK / FK)| FOO(FK)
PK - >主键
FK - >外键
我不能简单地这样做: (
$ CompositeId()。 KeyReference(a => a.FOO)
.KeyReference(a => a.CLIENT);
HasMany(a => a.B);
$ b class BMap
{
public BMap()
{
CompositeId()。 KeyReference(a => a.BAR)
.KeyReference(a => a.CLIENT);
参考文献(a => a.A);
$ b $ p
$ b $ p $将会失败,出现以下异常:
$ b
外键(FKE7804EB3DA7EBD4B:B [FOO]))必须与引用的主键(A [FOO,CLIENT])具有相同的列数
是否可以正确映射nhibernate?
解决
$ b
$ b
HasMany(a => aB).KeyColumns.Add( FOO,CLIENT)。Cascade.All();
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])) 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();
这篇关于如何将复合主键映射到外部流利的nhibernate?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文