Very slow ToListAsync() compared to ToList()

asp.net-core-mvc entity-framework-core

Question

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;
1
3
11/10/2015 4:16:44 PM

Popular Answer

As reported in this SO answer, if you're using large column types (blobs, varchar(max), etc.), Entity Framework 6 will perform poorly when using ToListAsync(). I can't say I 100% understand the intricacies which make this the case, but suffice it to say you are correct to use ToList() if you're retrieving large data values like this.

0
9/16/2019 3:27:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow