I'm trying to map a couple of legacy tables using Entity Framework. The classes look like this...
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; }
}
Each Customer has one "BillToAddress
" that corresponds with an Address whose CustomerReferenceCode
contains the Customer's Code and where the Type field contains the text "Customer
"
Each Customer
has zero or more "ShipToAddresses
" that correspond to Addresses
whose CustomerReferenceCode
contains the Customer's Code and whose where the Type fields contain the text "Ship-To
"
I'm able to reference the BillToAddress
by adding
[Key, Required]
[ForeignKey("BillToAddress"), Column(Order = 1)]
public string Code { get; set; }
[ForeignKey("BillToAddress"), Column(Order = 2)]
public string Domain { get; set; }
But I've not been able to figure out how to reference the collection of ShipToAddresses
for the customer.