I'm studying C# 8 and new we have a new interface call IAsyncEnumerable and I was think maybe it's a good ideia create a new interface call IAsyncQueryable to be possible using await foreach async with ORM like EF or NHibernarte:
IAsyncQueryable query = database.Where(...);
await foreach(var a in query) {
...
}
I was thinking IAsyncQueryable could be:
public interface IAsyncQueryable : IAsyncEnumerable
{
Type ElementType { get; }
Expression Expression { get; }
IQueryProvider Provider { get; }
}
public interface IAsyncQueryable<T> : IAsyncQueryable, IAsyncEnumerable<T>
{
}
or
public interface IAsyncQueryable : IQueryable, IAsyncEnumerable
{
}
public interface IAsyncQueryable<T> : IQueryable<T>, IAsyncQueryable, IAsyncEnumerable<T>
{
}
Since IQueryable is about composing a query rather than constructing an execution pipeline, it would probably make more sense to follow the current Approach (used by EF) of adding an extension like this
public static IAsyncEnumerable<TSource> AsAsyncEnumerable<TSource>(this IQueryable<TSource> source)
The async enumerable implementation is developed in the dotnet/reactive repo. And there actually is already an IAsyncQueryable interface:
cc @stephentoub
Without language support for awaits in expression trees, I don't think there's much that can or should be done here.
cc: @cston, @jaredpar
I agree. There is currently no plans to invest in our expression tree support at this time.
@jaredpar should we move this issue to your repo you may track it for the future if anything change?
Either way. This is one of those features that crosses our repositories so I'm fine with it being here or there.
Thanks @jaredpar I'll move it because corefx can support it if the it is decided from your side to support it.
Issue moved to dotnet/roslyn dotnet/runtime#27516 via ZenHub
Since IQueryable is about composing a query rather than constructing an execution pipeline, it would probably make more sense to follow the current Approach (used by EF) of adding an extension like this
public static IAsyncEnumerable<TSource> AsAsyncEnumerable<TSource>(this IQueryable<TSource> source)
IQueryable/LINQ supposes to abstract queries but at the same time, we have to add a reference to the entity framework? Where is the separation of concern part here? An application layer should be unaware of any underlying infrastructure! You promoting unportable code.
@NimaFx - No, I believe what they meant was "EF adds a method to turn IQueryable into IEnumerable, so we should probably add one to turn it into IAsyncEnumerable".
Most helpful comment
Since IQueryable is about composing a query rather than constructing an execution pipeline, it would probably make more sense to follow the current Approach (used by EF) of adding an extension like this