我想弄清楚,如何实现导航属性到我的实体......但是我的导航性能总是空: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