Runtime: Suggestion: IAsyncQueryable

Created on 19 Dec 2018  路  11Comments  路  Source: dotnet/runtime

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

}
api-suggestion area-System.Threading.Tasks

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

public static IAsyncEnumerable<TSource> AsAsyncEnumerable<TSource>(this IQueryable<TSource> source)

All 11 comments

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:

https://github.com/dotnet/reactive/blob/IxAsyncCSharp8/Ix.NET/Source/System.Linq.Async.Queryable/System/Linq/IAsyncQueryable.cs

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.

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".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nalywa picture nalywa  路  3Comments

chunseoklee picture chunseoklee  路  3Comments

btecu picture btecu  路  3Comments

jkotas picture jkotas  路  3Comments

matty-hall picture matty-hall  路  3Comments