I have been scouring the internet for a solution to my problem, but have found nothing yet that works.
I have a query that selects a new DTO like so:
List<myDTO> query = (from c in db.Customers
.Include(x => x.Orders)
where customerId = 5
select new myDTO
{
Customer = c,
...
}).ToListAsync();
foreach (var custDto in query)
{
//this is lazy loaded
var customerOrder = custDto.Customers.Orders;
}
My problem is when I try to navigate to query.Customers.Orders it is lazy loaded. I would like to eager load the Orders property so it doesn't hit the database many times when looping through customers. I thought having the include would eager load the navigation property.
I am aware I can possibly put an order property in myDTO and load it that way, but I am curious if it's possible the above way.
Thanks!