如何首先在Entity Framework数据库中的同一个表上使用1-1映射?

时间:2014-01-28 19:24:53

标签: entity-framework-4.1 parent-child

我有一个情况,我有一个联系人和一个映射的联系人。映射的联系人可能存在,但它可能为空。

这是一个0..1:1的映射,所以我只是添加了一个MappedContactId,它将FK返回到contacts表的Id。

Contact
-----------------------
Id  bigint not-null PK  <----------|
MappedContactId bigint null FK ----|

实体框架迫使我将其映射为1:多关系。如果我尝试将其映射为零或1个联系人,我会收到错误:

Multiplicity is not valid in Role 'MappedContact' in relationship
FK_Contact_MappedContact'. Because the Dependent Role properties are not the key
properties, the upper bound of the multiplicity of the Dependent Role must be *.    

有没有办法让这个回到零或1,或者我坚持1:很多?

0 个答案:

没有答案
相关问题