Reputation: 33
I have the following and wish to implement paging but I get an error when doing so. I do not receive this error when I perform the paging directly on a query result that returns from LINQ as IQueryable, only when I create an IQueryable from a List (or IEnumerable)
System.InvalidOperationException: The source IQueryable doesn't implement IDbAsyncEnumerable. Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations. For more details see http://go.microsoft.com/fwlink/?LinkId=287068
List<WeeklyBilling> wbs = new List<WeeklyBilling>();
foreach (Trucks t in trucks)
{
WeeklyBilling wb = new WeeklyBilling();
wb.Customer = t.Customer;
wbs.Add(wb);
}
var wbitems = await wbs.AsQueryable<WeeklyBilling>()
.OrderBy(input.Sorting)
.PageBy(input)
.ToListAsync();
Upvotes: 2
Views: 3347
Reputation: 436
Refer to the official docs.
Because the Entity Framework queries make use of LINQ, the extension methods are defined on IQueryable and IEnumerable. However, because they are only designed to be used with Entity Framework, you may receive the following error if you try to use them on a LINQ query that isn’t an Entity Framework query.
You can also replace PageBy with the Skip and Take extension methods or other solutions.
var wbitems = wbs.OrderBy(input.Sorting)
.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage)
.ToList();
Upvotes: 6