I have a Customer that can have a Billing or Shipping address. The Customer has the BillingAddressId and ShippingAddressId that corresponds to an AddressId on the Address table.
I've tried the below setup but keep getting errors:
public class Customer
[Key]
public int CustomerId { get; set; }
[Column("billingAddressId")]
[ForeignKey("Address")]
public int BillingAddressId { get; set; }
[Column("shippingAddressId")]
public int ShippingAddressId { get; set; }
public virtual Address BillingAddress { get; set; }
public virtual Address ShippingAddress { get; set; }
with the Address looking like this:
public class Address
[Key]
public int AddressId {get;set;}
public virtual Customer Customer { get; set; }
My model builder:
modelBuilder.Entity<Customer>()
.HasOptional(c => c.BillingAddress)
.WithOptionalPrincipal(a => a.Customer);
But I keep getting this error The ForeignKeyAttribute on property 'BillingAddressId' on type '...Customer' is not valid. The navigation property 'Address' was not found on the dependent type '...Customer