【发布时间】:2011-07-30 02:30:57
【问题描述】:
我试图弄清楚如何为将生成 SQL 表的 2 个模型(实体)设置导航属性。场景:我有一个货物和一个公司模型/实体。我需要将 Shipment 模型中的 3 个属性 ClientID¸ ShipperID 和 ConsigneeID 关联到 Company 模型中的 CompanyID。现在,Shipment 模型的正确导航属性是什么?上下文会是什么样子?
public virtual ICollection< Company > Companies { get; set; }
OR
public virtual Company Company { get; set; }
以下是 2 个模型:
public class Shipment
{
public int ShipmentID { get; set; }
public string Name { get; set; }
public DateTime DateStamp { get; set; }
public int ClientID { get; set; }
public int ShipperID { get; set; }
public int ConsigneeID { get; set; }
public virtual ICollection< Company > Companies { get; set; }
OR
public virtual Company Company { get; set; }
}
public class Company
{
public int CompanyID { get; set; }
public string Name { get; set; }
public DateTime DateStamp { get; set; }
public virtual ICollection< Shipment > Shipments { get; set; }
}
【问题讨论】:
标签: entity-framework asp.net-mvc-3