我想弄清楚,如何實現導航屬性到我的實體......但是我的導航性能總是空:EF CodeFirst - 添加ICollection的導航屬性
我已經設置了兩個實體:
實體1包含此行:
public int Id { get; set; }
public ICollection<BestellterArtikel> BestellteArtikel { get; set; }
我的第二個實體看起來是這樣的:
public int Id { get; set; }
public int BestellungId { get; set; }
public Bestellung BestellteArtikel { get; set; }
進一步包括我此行我的覆蓋OnModelCreating法:
modelBuilder.Entity<Bestellung>().HasMany(e => e.BestellteArtikel).WithRequired(e => e.Bestellung);
我做了什麼錯?我忘記了一些重要的事情嗎?它是否必須如此複雜?我必須在每個屬性的覆蓋方法中添加一行嗎?
叫什麼名字?如果您的意思是「虛擬」,那麼它就是一個C#關鍵字,並且在EF模型中使用它意味着延遲加載引用。 –
等一下!你的映射有問題。我編輯了我的答案 –
不,您還沒有正確理解我的意思:我有一個名爲BestellterArtikel的實體(照顧R!)與財產「Bestellung」和一個實體Bestellung與ICollection「BestellteArtikel」(沒有R!)。 。我不能重命名這些屬性,就像你在代碼中做的那樣...;) – Jannik