I am trying to include two relationships with the Include() method.
using (var db = new DBContext()) {
var result = db.ProduktKundeArtNummer
.Include(p => p.Kunde)
.Include(d => d.Produkt)
.ToList();
}
}
When I execute this snippet I get the following error message:
Lambda expression used inside Include is not valid.
I created my context by scaffolding my mysql database.
This is the class it is referring to:
public partial class ProduktKundeArtNummer {
[Key]
public int Produkt { get; set; }
[Key]
public int Kunde { get; set; }
[Required]
[StringLength(255)]
public string Artikelnummer { get; set; }
[ForeignKey(nameof(Kunde))]
[InverseProperty("ProduktKundeArtNummer")]
public virtual Kunde KundeNavigation { get; set; }
[ForeignKey(nameof(Produkt))]
[InverseProperty("ProduktKundeArtNummer")]
public virtual Produkt ProduktNavigation { get; set; }
}
I already googled a lot and as far as I know my snippet should work. Does anyone know where I messed up?
Edit: Using a string navigator works fine, but I would rather use the lambda expressions.
using (var db = new DBContext()) {
var result = db.ProduktKundeArtNummer
.Include("KundeNavigation")
.Include("ProduktNavigation")
.ToList();
}
}