NHibernate 映射:如何根据字段值映射行

发布于 2024-09-18 20:09:49 字数 706 浏览 1 评论 0原文

我有一个 [ContactNumbers] 表,定义如下:

ID (PK) | PersonID (FK) | NumberType | Number
========|===============|============|=======

以及一个定义为的类:

public class Person
{
    ContactNumber homePhone;
    ContactNumber workPhone;
}

public class ContactNumber
{
    string Number;
}

我如何为 PersonContactNumber 类,以便将 Person.homePhone 映射到 [ContactNumbers] 表中观察到 FK 的相应行,以及 [ContactNumbers].[NumberType] 等于“HOME”? ([NumberType]Person.workPhone"WORK"。)

我已经花了很多时间来研究这个问题,我暂时还没有找到解决办法。

I have a [ContactNumbers] table as defined below:

ID (PK) | PersonID (FK) | NumberType | Number
========|===============|============|=======

and a classes defined as:

public class Person
{
    ContactNumber homePhone;
    ContactNumber workPhone;
}

public class ContactNumber
{
    string Number;
}

How would I define my HBM mapping/s for the Person and ContactNumber class so that Person.homePhone is mapped to the corresponding row in the [ContactNumbers] table with the FK observed, and [ContactNumbers].[NumberType] equal to "HOME"? ([NumberType] is "WORK" for Person.workPhone.)

Already spent a good deal of the day just looking into this, and I couldn't find a solution just yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

无声情话 2024-09-25 20:09:49

您不能将单个实体/实例映射到多行,反之亦然。

您可以做的是这样做:

class Person
{
  public IList<ContactNumber> ContactNumbers { get; set; }
}

然后将 ContactNumbers 类映射为集合/单对多关联。 PersonID 列被列为外键,所以我假设有一个人员表?

You cannot map single entity / instance to multiple rows and vice versa.

What you can do is do this:

class Person
{
  public IList<ContactNumber> ContactNumbers { get; set; }
}

And then map the ContactNumbers class as a collection / ony-to-many association. The PersonID column is listed as a foriegn key so I assume there is a person table?

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