NHibernate 映射:如何根据字段值映射行
我有一个 [ContactNumbers]
表,定义如下:
ID (PK) | PersonID (FK) | NumberType | Number
========|===============|============|=======
以及一个定义为的类:
public class Person
{
ContactNumber homePhone;
ContactNumber workPhone;
}
public class ContactNumber
{
string Number;
}
我如何为 Person
和 ContactNumber 类,以便将
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将单个实体/实例映射到多行,反之亦然。
您可以做的是这样做:
然后将 ContactNumbers 类映射为集合/单对多关联。 PersonID 列被列为外键,所以我假设有一个人员表?
You cannot map single entity / instance to multiple rows and vice versa.
What you can do is do this:
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?