dotvvm
dotvvm copied to clipboard
Async version of LoadFromQueryable
GridViewDataSet
doesn't have the async version of LoadFromQueryable
. We should add it.
We can not, IQueryable<T>
nor the IQueryProvider
does not have any async method - https://docs.microsoft.com/cs-cz/dotnet/api/system.linq.iqueryable-1, https://docs.microsoft.com/cs-cz/dotnet/api/system.linq.iqueryable-1?view=netframework-4.7.2
We can create a new package with extensions for EntityFramework. But this method cannot be included in DotVVM Framework package directly. As @exyi mentioned, IQueryable<T>
does not provide any async method.
I think that sharing some little snippet that solves the problem would be better than a package as it will let people not using EF change some detail and make it work for them. It may look like this for some hypotetical ORM that needs a IAsyncQueryExecutor
public Task LoadFromQueryable(IQueryable<T> source, IAsyncQueryExecutor e)
{
source = ApplyFilteringToQueryable(source);
var itemsTask = e.GetListAsync(ApplyOptionsToQueryable(source));
var totalItemsTask = e.GetCountAsync(source);
await Task.WhenAll(itemsTask, totalItemsTask);
Items = itemsTask.Result;
PagingOptions.TotalItemsCount = totalItemsTask.Result;
IsRefreshRequired = false;
}
I have found the System.Linq.Async package that should add ToListAsync
- it's prerelease and unlisted now, but it's there.
We should explore whether this can help us.
In EF Core, the IQueryable implements IAsyncEnumerable which is in the standard. This means that we can actually implement this method (at least for netstandard2.1 version)
Ok, it's not that easy since we also need to call the .Count()
method, which does not have an async variant in netstandard2.1 :|