dataobjects-net
dataobjects-net copied to clipboard
EntitySet and ToListAsync extension method runtime error
Hi,
In my company we are migrating to DataObjects v7, but we encountered some problems concerning the AsAsync extension method that seemed to disappear, and that we used everywhere (on IQueryable<T> or EntitySet<T> objects). It seems that we can use ToListAsync instead, but we have a problem when using it on EntitySet.
When reading the code of EntitySet, we expected ToListAsync to work since EntitySet<T> implements IQueryable<T>, but there is a runtime error because EntitySet does not implement IAsyncEnumerable. Is there a reason why EntitySet<T> does not implement IAsyncEnumerable<T>?
After reading the implementation of Queryable<T>.GetAsyncEnumerator, I think we could do the same in the EntitySet<T> class (that is using EntitySet.Provider to get the same result):
public async IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
var result = await Provider.ExecuteSequenceAsync<T>(expression, cancellationToken).ConfigureAwait(false);
var asyncSource = result.AsAsyncEnumerable().WithCancellation(cancellationToken).ConfigureAwait(false);
await foreach (var element in asyncSource) {
yield return element;
}
}
But maybe we are missing something that prevents us to do so.
We found a small workaround (myEntitySet.Where(x => 1 == 1).ToListAsync()) for the moment, but I would greatly appreciate some explanation.
Thanks a lot, Alex