【发布时间】:2011-03-18 08:58:44
【问题描述】:
这是我的模型:
public class Customer
{
public int ID { get; set; }
public int MailingAddressID { get; set; }
public virtual Address MailingAddress { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
}
public class Address
{
public int ID { get; set; }
public int CustomerID { get; set; }
public virtual Customer Customer { get; set; }
}
一个客户可以有任意数量的地址,但是这些地址中只有一个可以是邮寄地址。
如果我只使用一个关系,我可以让一对一关系和一对多工作得很好,但是当我尝试同时引入这两者时,我会在地址表上获得多个 CustomerID 键(CustomerID1、CustomerID2、CustomerID3)。我真的把我的头发扯掉了。
为了映射一对一关系,我使用这里描述的方法http://weblogs.asp.net/manavi/archive/2011/01/23/associations-in-ef-code-first-ctp5-part-3-one-to-one-foreign-key-associations.aspx
【问题讨论】:
标签: c# entity-framework entity-framework-ctp5