Skip to content

Commit

Permalink
Update async docs for the new .NET IAsyncEnumerable LINQ operators (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Jan 22, 2025
1 parent d4254f3 commit 0778a5c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 67 deletions.
18 changes: 15 additions & 3 deletions entity-framework/core/miscellaneous/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ Note that there are no async versions of some LINQ operators such as <xref:Syste
## Client-side async LINQ operators

The async LINQ operators discussed above can only be used on EF queries - you cannot use them with client-side LINQ to Objects query. To perform client-side async LINQ operations outside of EF, use the [`System.Linq.Async` package](https://www.nuget.org/packages/System.Linq.Async); this package can be especially useful for performing operations on the client that cannot be translated for evaluation at the server.
In certain cases, you may want to apply client-side LINQ operators to results coming back from the database; this is needed especially when you need to perform an operation that cannot be translated to SQL. For such cases, use <xref:Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AsAsyncEnumerable*> to execute the query on the database, and continue composing client-side LINQ operators over the resulting <xref:System.Collections.Generic.IAsyncEnumerable`1>. For example, the following executes a local .NET function on the asynchronous results of the EF LINQ query:

In EF Core 6.0 and lower, referencing `System.Linq.Async` unfortunately causes ambiguous invocation compilation errors on LINQ operators applied to EF's DbSets; this makes it hard to use both EF and `System.Linq.Async` in the same project. To work around this issue, add <xref:System.Linq.Queryable.AsQueryable*> to your DbSet:
```c#
var blogs = context.Blogs
.Where(b => b.Rating > 3) // server-evaluated (translated to SQL)
.AsAsyncEnumerable()
.Where(b => SomeLocalFunction(b)); // client-evaluated (in .NET)
[!code-csharp[Main](../../../samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs#SystemInteractiveAsync)]
await foreach (var blog in blogs)
{
// ...
}

```

> [!NOTE]
> LINQ operators over <xref:System.Collections.Generic.IAsyncEnumerable`1> were introduced in .NET 10. When using an older version of .NET, reference the [`System.Linq.Async` package](https://www.nuget.org/packages/System.Linq.Async).

This file was deleted.

41 changes: 0 additions & 41 deletions samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs

This file was deleted.

7 changes: 0 additions & 7 deletions samples/core/Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collations", "Miscellaneous
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Async", "Miscellaneous\Async\Async.csproj", "{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncWithSystemInteractive", "Miscellaneous\AsyncWithSystemInteractive\AsyncWithSystemInteractive.csproj", "{70E581C3-38BB-46CC-9063-ADF9F2B76570}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Spatial", "Spatial", "{B3714D90-F595-4644-8018-ADE19D66B853}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServer", "Spatial\SqlServer\SqlServer.csproj", "{849357D0-85B3-4326-9D42-AD5A09E9613C}"
Expand Down Expand Up @@ -265,10 +263,6 @@ Global
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Release|Any CPU.Build.0 = Release|Any CPU
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Release|Any CPU.Build.0 = Release|Any CPU
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -575,7 +569,6 @@ Global
{FE71504E-C32B-4E2F-9830-21ED448DABC4} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
{62C86664-49F4-4C59-A2EC-1D70D85149D9} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
{70E581C3-38BB-46CC-9063-ADF9F2B76570} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
{849357D0-85B3-4326-9D42-AD5A09E9613C} = {B3714D90-F595-4644-8018-ADE19D66B853}
{59588FC9-0A4F-4903-84B0-A2CB2EE6F9AC} = {B3714D90-F595-4644-8018-ADE19D66B853}
{524AE4A6-A15F-466C-AED3-CDF3209E4394} = {1AD64707-0BE0-48B0-A803-916FF96DCB4F}
Expand Down

0 comments on commit 0778a5c

Please sign in to comment.