1 対 1 の関係を築いている人々に関する Google と SO のページをすべて読んでいますが、うまくいきEFません。
これが私のモデルです:
アカウント:
public int Id {get; set;}
public virtual AccountConfig AccountConfig {get; set;}
アカウント マップ:
HasKey(t => t.Id);
HasRequired(t => t.AccountConfig)
.WithOptional();
アカウント構成:
public int Id {get; set;}
public int AccountId {get; set;}
public virtual Account Account {get; set;}
アカウント構成マップ:
HasKey(t => t.Id);
HasRequired(t => t.Account)
.WithOptional(t => t.AccountConfig);
実行すると、 on のAccountConfigプロパティAccountは でNULLあり、Accounton のプロパティAccountConfigは正しくないレコードです (偶然にも、取得されAccount.Idた は と同じですがAccountConfig.Id、それが何かを意味するかどうかはわかりません)。
データベースでは、テーブルにはレコードAccountへの参照はありませんが、テーブルには列を使用してレコードへの参照があります。AccountConfigAccountConfigAccountAccountId
最終結果は、 from への参照と (可能であれば) from への参照を持つことになりAccountConfigます。AccountAccountAccountConfig