2
我有以下情形6單向關係首先,我試圖創建一個單向的關係小部件與顏色類的匹配與HeaderBackgroundColor/HeaderBackgroundColorID字段。實體框架使用代碼首先
通常我會在配置類做到這一點:
this.HasOptional(r => r.HeaderBackgroundColor)
.WithMany(m => m.Widgets)
.HasForeignKey(fk => fk.HeaderBackgroundColorID);
,但我不是在添加Widgets集合到Color類intrested。 試過這個:
this.HasOptional(r => r.HeaderBackgroundColor)
.WithMany()
.HasForeignKey(fk => fk.HeaderBackgroundColorID);
但是引發了驗證錯誤。
這樣做的方式是什麼?
那麼這確實是問題的一部分。另一個問題是我沒有將HeaderBackgroundColor標記爲虛擬屬性。 – kob490