Entity Framework one-to-one relationship mapping flattened in code
- by Josh Close
I have a table structure like so.
Address:
AddressId int not null primary key identity
...more columns
AddressContinental:
AddressId int not null primary key identity foreign key to pk of Address
County
State
AddressInternational:
AddressId int not null primary key identity foreign key to pk of Address
ProvinceRegion
I don't have control over schema, this is just the way it is.
Now, what I want to do is have a single Address object.
public class Address
{
public int AddressId { get; set; }
public County County { get; set; }
public State State { get; set }
public ProvinceRegion { get; set; }
}
I want to have EF pull it out of the database as a single entity. When saving, I want to save the single entity and have EF know to split it into the three tables.
How would I map this in EF 4.1 Code First?
I've been searching around and haven't found anything that meets my case yet.
UPDATE
An address record will have a record in Address and one in either AddressContinental or AddressInternational, but not both.