I'm having trouble finding the right combination of Fluent methods to map my classes appropriately. Here's basically what I'm trying to do:
Person table: PersonID, HomeAddressID (nullable), WorkAddressID (nullable)
Address table: AddressID, Street, etc...
The Person
class has an Address HomeAddress
and an Address WorkAddress
property, but not the integer properties for the IDs.
The Address
class does not have any properties for its related Person
entities.
I'm not finding any examples online for this scenario, and I'm just not finding the right combination. Code-first configuration has always done a good job confusing me.
This is the closest to one of the examples I found, but I'm getting Invalid column name 'HomeAddressID'
, which tells me I'm probably mapping the wrong side of the relationship.
public class PersonConfiguration : EntityTypeConfiguration<Person>
{
// other mappings
HasOptional(p => p.HomeAddress)
.WithOptionalPrincipal()
.Map(x => x.MapKey("HomeAddressID"));
HasOptional(p => p.WorkAddress)
.WithOptionalPrincipal()
.Map(x => x.MapKey("WorkAddressID"));
}
Am I on the right track?