I keep getting errors like
: The property expression 'met => {from TrM x in met select [x].Tm}' is not valid. The expression should represent a property access: 't => t.MyProperty'.
I have a class structure of
public class Tr: BaseModel
{
public int Id{ get; set; }
public List<Trm> Mets { get; set; } = new List<Trm>();
[JsonIgnore]
public Test TestDef { get; set; }
}
public class Trm: BaseModel
{
public Tm tm { get; set; }
}
public class Tm: BaseModel
{
[JsonIgnore]
public T TestDef { get; set; }
}
I want to be able to say when loading Tr load all Trm and include Tm when loading.
I have tried the following
var results = await _dbContext.Tr
.Include(tr => tr.Mets ).ThenInclude(met => met.Select(x=> x.tm))
.Include(tr => tr.TestDef)
.AsNoTracking()
.ToListAsync();
return results;
How would I do this?
Thanks
You can't use Select
for Include
in Ef Core. You should drill down to load related data by using ThenInclude
.
var results = await _dbContext.Tr
.Include(tr => tr.Mets )
.ThenInclude(met => met.tm)
.Include(tr => tr.TestDef)
.AsNoTracking()
.ToListAsync();
Here is the offical documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With