0

エンティティにナビゲーション プロパティを実装する方法を理解しようとしていますが、ナビゲーション プロパティは常に null です。

2 つのエンティティを設定しました。

エンティティ 1 には次の行が含まれます。

    public int Id { get; set; }
    public ICollection<BestellterArtikel> BestellteArtikel { get; set; }

私の 2 番目のエンティティは次のようになります。

    public int Id { get; set; }
    public int BestellungId { get; set; }
    public Bestellung BestellteArtikel { get; set; }

さらに、上書きした OnModelCreating-Method に次の行を含めました。

    modelBuilder.Entity<Bestellung>().HasMany(e => e.BestellteArtikel).WithRequired(e => e.Bestellung);

私は何を間違えましたか?私は何か重要なことを忘れていますか?そして、それはそれほど複雑でなければなりませんか?プロパティごとに上書きされたメソッドに行を追加する必要がありますか?

4

2 に答える 2

1

ここに私の解決策があります:

エンティティ 1:

  public virtual ICollection<BestellterArtikel> BestellteArtikel { get; set; }

エンティティ 2:

  public virtual  Bestellung BestellteArtikel { get; set; }

編集:

また、マッピングを修正する必要があります。

modelBuilder.Entity<Bestellung>().HasMany(e => e.BestellteArtikel).WithRequired(e => e.BestellteArtikel );

BestellteArtikel プロパティを参照する代わりに、型を参照しました!

于 2013-05-31T07:23:10.520 に答える