I have a complex LINQ query with grouping and multiple includes. I found out that ToListAsync() takes more then second to complete, while ToList() returns in a fraction of second.
allReservationsList = allReservations.ToList(); // fast
allReservationsList = await allReservations.ToListAsync(); // more then a second for 60 rows
Am I doing anything wrong or is it an issue with entity framework?
Here is the query:
var reservations = db.Reservations
.Include(r => r.PickUpLocation)
.Include(r => r.ReturnLocation)
.Include(r => r.RequestedVehicleModel).ThenInclude(m => m.Photos)
.Include(r => r.RequestedVehicleModel.VehicleType.VehicleModels)
.Include(r => r.RequestedVehicleType).ThenInclude(t => t.Photos)
.Include(r => r.AssignedUnit.VehicleModel.VehicleType)
.Include(r => r.DailyPrice.Currency);
var allReservations =
from r in reservations
orderby r.VersionDate descending
group r by r.BookingCode into g
select g;