EFリレーションはDBリレーションに厳密に従うため、マッピングを介してこれを行うことはできません。さらに、EFの1対1の関係は、従属テーブルの主キーに外部キーを配置することに基づいており(住所と人はまったく同じ主キー値を持っている必要があります)、この要件は、テーブルも。
私はこのアプローチを試します(テストされていません):
public class MyContext : DbContext {
public MyContext() {
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized +=
(sender, e) => {
var person = e.Person as Person;
if (person != null) {
// Fill the property manually
person.Address = this.Addresses.FirstOrDefault(/* some condition */);
}
}
protected override void OnModelCreating(DbModelBuilder builder) {
// Do not map the propery
builder.Entity<Person>().Ignore(p => p.Address);
// other mapping
}
public override int SaveChanges() {
// TODO: here you must have your own change tracking logic
// for address to know when the address has changed and
// new record must be created in the database for old address
return base.SaveChanges();
}
// rest of context class
}