我想弄清楚如何设置将生成SQL表的2个模型(实体)的导航属性。场景:我有一个货件和一个公司模型/实体。我需要将Shipment模型中的3个属性ClientIDF ShipperID和ConsigneeID绑定到公司模型中的CompanyID。现在什么是Shipment模型的正确导航属性以及Context将会是什么样子?实体框架4/MVC3导航属性困境
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; }
}
切记要以此为答案,如果解决了你问题! –