dotvvm icon indicating copy to clipboard operation
dotvvm copied to clipboard

Async version of LoadFromQueryable

Open tomasherceg opened this issue 6 years ago • 6 comments

GridViewDataSet doesn't have the async version of LoadFromQueryable. We should add it.

tomasherceg avatar Feb 20 '19 20:02 tomasherceg

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

exyi avatar Feb 20 '19 21:02 exyi

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.

quigamdev avatar Feb 22 '19 12:02 quigamdev

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;
}

exyi avatar Feb 22 '19 13:02 exyi

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.

tomasherceg avatar Mar 31 '19 15:03 tomasherceg

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)

exyi avatar Oct 24 '21 12:10 exyi

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 :|

exyi avatar Oct 24 '21 17:10 exyi