CodeFirst一对一关系问题 [英] CodeFirst one-to-one relationship question

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

问题描述

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


BusinessEntity(表)

    BusinessEntityId Int(PK,Identity)

 

人(表)

   BusinessEntityId int(PK,带有BusinessEntity表的参考)

   FullName varchar(255)


此处Person表没有自动生成的Id,而是引用BusinessEntity表。


如果我使用Fluent NHibernate上面的映射将是
  Id(x => x.BusinessEntityId)

        .GeneratedBy.Foreign(" BusinessEntity");


如何在codefirst CTP 4中映射它?

AdventureWorks2008是一个复杂的关系设计,如果来自EF团队的人可以使用CodeFirst映射该数据库,那么这将是最好的例子。


谢谢


Ashraf。


 


 


 

解决方案

如果我没有弄错,在这个模型中,Person是一个BusinessEntity(因此BusinessEntityID是PK)。我会将其建模为继承的实体关系 人:的BusinessEntity


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)

Here Person table do not have auto generated Id, instead it reference to BusinessEntity table.

If I use Fluent NHibernate the mapping for the above would be
  Id(x => x.BusinessEntityId)
        .GeneratedBy.Foreign("BusinessEntity");

How do I map it in codefirst CTP 4?
AdventureWorks2008 is a complex relational design, if someone from EF team can map that database using CodeFirst, then that would be the best example.

Thanks

Ashraf.

 

 

 

解决方案

If I'm not mistaken, in this model Person IS A BusinessEntity (hence the BusinessEntityID being the PK). I would model it as an inherited entity relationship  Person:BusinessEntity.


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

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