流利的NHibernate一对一的关系? [英] fluent NHibernate one-to-one relationship?

查看:122
本文介绍了流利的NHibernate一对一的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有AdventureWorks2008数据库中的以下关系表。

b
$ b $ $ $ $ $ $ $ $














$ BusinessEntityId int(PK,具有BusinessEntity表的引用)
FullName varchar(255)

在BusinessEntity表和Person表之间是一对一的。



如何在Person表中没有任何额外字段(如Id)的流畅映射?



对于Person,应该有两个类,一个是BusinessEntity,另一个是适当的模型,以最好地描述上述关系。

谢谢,
Ashraf。

解决方案

假设您的Person映射非常标准,您这样做的方式是说:

  Id(x => x.BusinessEntityId)
.GeneratedBy.Foreign(BusinessEntity);

在Person类中。

假定您的Person类有一个名为BusinessEntity的属性,类型为BusinessEntity。



您还需要将BusinessEntity映射到约束设置为true的Person他们的主键是对BusinessEntity的外键引用)。

关键是GeneratedBy.Foreign()表示您的身份是通过链接生成的另一个班。

I have a problem with one-to-one relationships in the fluent nHibernate.

I have the following relational table from the AdventureWorks2008 database.

BusinessEntity (Table)
    BusinessEntityId Int (PK, Identity)

Person (Table)
   BusinessEntityId int (PK, Reference with BusinessEntity table)
   FullName varchar(255)

The relationship between BusinessEntity table and Person table is one-to-one.

How do I map fluently without any extra field like "Id" in the Person table?

There should be 2 class one for Person and another for BusinessEntity, or an appropriate model to best describe the above relation.

Thanks, Ashraf.

解决方案

presuming your Person mapping is pretty standard, the way you do this is by saying:

Id(x => x.BusinessEntityId)
     .GeneratedBy.Foreign("BusinessEntity");

on the Person class.

This presumes that your Person class has a property called BusinessEntity which is of type BusinessEntity.

You'll also need to map BusinessEntity to Person with constrained set to true (to say that they primary key of Person is a foreign key reference to BusinessEntity).

The key thing is the GeneratedBy.Foreign() to say that your identity is generated by a link to another class.

这篇关于流利的NHibernate一对一的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆