Fluent NHibernate 从继承的复合 ID 映射复合 ID
假设我有一个包含以下 3 个表的现有数据库:
Table1:
(PK)T1ID1
(PK)T1ID2
表2:
(PK)T2ID1
表3:
(FK)T1ID1
(FK)T1ID2
(FK)T2ID1 (其中 3 个键来自上表)
我的问题是:如何使用 Fluent NHibernate 映射 Table3?
让我感到困惑的是如何处理它的复合键来自两个不同的表的事实。
我有以下表 1 和表 2 的映射:
public class Table1
{
public virtual long T1ID1 { get; set; }
public virtual long T1ID2 { get; set; }
}
public class Table2
{
public virtual long T2ID1 { get; set; }
}
public class Table1Map
{
public Table1Map()
{
Table("Table1");
CompositeId()
.KeyProperty(x => x.T1ID1, "T1ID1")
.KeyProperty(x => x.T1ID2, "T1ID2");
}
}
public class Table2Map
{
public Table2Map()
{
Table("Table2");
Id(x => x.T2ID1, "T2ID1");
}
}
Let's say I have an existing database with the following 3 tables:
Table1:
(PK)T1ID1
(PK)T1ID2
Table2:
(PK)T2ID1
Table3:
(FK)T1ID1
(FK)T1ID2
(FK)T2ID1
(Where the 3 keys come from the tables above)
My question is: How do I map Table3 with Fluent NHibernate?
What is confusing to me is what to do about the fact that its composite keys come from 2 different tables.
I have the following for the mappings for tables 1 and 2:
public class Table1
{
public virtual long T1ID1 { get; set; }
public virtual long T1ID2 { get; set; }
}
public class Table2
{
public virtual long T2ID1 { get; set; }
}
public class Table1Map
{
public Table1Map()
{
Table("Table1");
CompositeId()
.KeyProperty(x => x.T1ID1, "T1ID1")
.KeyProperty(x => x.T1ID2, "T1ID2");
}
}
public class Table2Map
{
public Table2Map()
{
Table("Table2");
Id(x => x.T2ID1, "T2ID1");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试查看 具有单列名称的 Fluent NHibernate 和复合 ID
我认为您想要的是“.KeyReference()”属性。
上面的链接使用的是旧版本的 FNH,但您需要关心的问题是方法名称略有不同。该文章的其余部分应该对您有所帮助。
让我知道你进展如何。
try looking at Fluent NHibernate and composite ID with single column name
I think what you're after is the ".KeyReference()" property.
The link above is using an old version of FNH but all you need to be concerned with , with regards to your issue is that the method names are slightly different. all the rest of that article should help you.
Let me know how you go.