CodeFirst一对一关系问题

编程入门 行业动态 更新时间:2024-10-24 08:21:10
本文介绍了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一对一关系问题

本文发布于:2023-11-16 11:50:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1604023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   CodeFirst

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!