C
C#16mo ago
127001

❔ EF | Get N level associated data

var data = dbContext.Orders
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.Category)
.Include(x => x.Customer)
.Include(x => x.Address)
.ToList();
var data = dbContext.Orders
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.Category)
.Include(x => x.Customer)
.Include(x => x.Address)
.ToList();
Data association is: Order -> OrderLine -> Product -> Category & ProductAdditionalInfos Products table has association to (1-N) ProductAdditionalInfos table which contains some information like Color, Size etc. How can I also add in this query ?
3 Replies
CupOfTea
CupOfTea16mo ago
I'm not sure, but I think that you can solve it by adding one more include with path:
var data = dbContext.Orders
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.Category)
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.ProductAdditionalInfos)
.Include(x => x.Customer)
.Include(x => x.Address)
.ToList();
var data = dbContext.Orders
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.Category)
.Include(x => x.OrderLines)
.ThenInclude(x => x.Product)
.ThenInclude(x => x.ProductAdditionalInfos)
.Include(x => x.Customer)
.Include(x => x.Address)
.ToList();
But I think there is different, more clear way to do that
FestivalDelGelato
that's a pretty standard way of doing it, to me
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?