我正在尝试使用实体框架映射几个遗留表。课程看起来像这样......
public class Customer
{
[Key, Required]
public string Code { get; set; }
public string Domain { get; set; }
public virtual Address BillToAddress { get; set; }
public virtual ICollection<Address> ShipToAddresses { get; set; }
}
public class Address
{
[Column(Order = 0), Key, Required]
public string Code { get; set; }
[Column(Order = 1), Key, Required]
public string Domain { get; set; }
public string Type { get; set; }
public string CustomerReferenceCode { get; set; }
}
每个客户都有一个“ BillToAddress
”,对应一个地址,该地址CustomerReferenceCode
包含客户代码,其中类型字段包含文本“ Customer
”
每个Customer
都有零个或多个“ ShipToAddresses
”,对应Addresses
于其CustomerReferenceCode
包含客户代码以及其类型字段包含文本“ Ship-To
”
我可以BillToAddress
通过添加来引用
[Key, Required]
[ForeignKey("BillToAddress"), Column(Order = 1)]
public string Code { get; set; }
[ForeignKey("BillToAddress"), Column(Order = 2)]
public string Domain { get; set; }
但我一直无法弄清楚如何为ShipToAddresses
客户引用集合。