Fluent NHibernate 从继承的复合 ID 映射复合 ID

发布于 2024-08-11 04:19:53 字数 842 浏览 2 评论 0原文

假设我有一个包含以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2024-08-18 04:19:53

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文