【发布时间】:2013-01-20 00:23:56
【问题描述】:
我有两个 POCO 课程:
订单类别:
public class Order
{
public int Id { get; set; }
public int? QuotationId { get; set; }
public virtual Quotation Quotation { get; set; }
....
}
引用类:
public class Quotation
{
public int Id { get; set; }
public virtual Order Order { get; set; }
....
}
- 每个
Order可以由一个或零个引号组成,并且 - 每个报价都可能导致订单。
所以我有一个“一或零”到“一或零”的关系,我该如何在EF Code first by Fluent API 中实现这一点?
【问题讨论】:
-
public virtual Quotation Quotation { get; set; },不是吗?你为什么不使用属性?为什么你的所有字段都是私有的? -
对不起,我编辑了我的属性代码。我的课程不是虚拟的。
-
它不是一个虚拟类,它是一个虚拟导航属性,在 Order 类中。
-
为清楚起见,您可以使用stackoverflow.com/a/45182785/1941942
标签: c# entity-framework ef-code-first entity-relationship fluent