Skip to content

Commit 0778a5c

Browse files
authored
Update async docs for the new .NET IAsyncEnumerable LINQ operators (#4937)
See dotnet/runtime#111685
1 parent d4254f3 commit 0778a5c

File tree

4 files changed

+15
-67
lines changed

4 files changed

+15
-67
lines changed

entity-framework/core/miscellaneous/async.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ Note that there are no async versions of some LINQ operators such as <xref:Syste
3737
3838
## Client-side async LINQ operators
3939

40-
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.
40+
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:
4141

42-
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:
42+
```c#
43+
var blogs = context.Blogs
44+
.Where(b => b.Rating > 3) // server-evaluated (translated to SQL)
45+
.AsAsyncEnumerable()
46+
.Where(b => SomeLocalFunction(b)); // client-evaluated (in .NET)
4347
44-
[!code-csharp[Main](../../../samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs#SystemInteractiveAsync)]
48+
await foreach (var blog in blogs)
49+
{
50+
// ...
51+
}
52+
53+
```
54+
55+
> [!NOTE]
56+
> 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).

samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj

Lines changed: 0 additions & 16 deletions
This file was deleted.

samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

samples/core/Samples.sln

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Collations", "Miscellaneous
3535
EndProject
3636
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Async", "Miscellaneous\Async\Async.csproj", "{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}"
3737
EndProject
38-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsyncWithSystemInteractive", "Miscellaneous\AsyncWithSystemInteractive\AsyncWithSystemInteractive.csproj", "{70E581C3-38BB-46CC-9063-ADF9F2B76570}"
39-
EndProject
4038
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Spatial", "Spatial", "{B3714D90-F595-4644-8018-ADE19D66B853}"
4139
EndProject
4240
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServer", "Spatial\SqlServer\SqlServer.csproj", "{849357D0-85B3-4326-9D42-AD5A09E9613C}"
@@ -265,10 +263,6 @@ Global
265263
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
266264
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
267265
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4}.Release|Any CPU.Build.0 = Release|Any CPU
268-
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
269-
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Debug|Any CPU.Build.0 = Debug|Any CPU
270-
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Release|Any CPU.ActiveCfg = Release|Any CPU
271-
{70E581C3-38BB-46CC-9063-ADF9F2B76570}.Release|Any CPU.Build.0 = Release|Any CPU
272266
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
273267
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Debug|Any CPU.Build.0 = Debug|Any CPU
274268
{849357D0-85B3-4326-9D42-AD5A09E9613C}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -575,7 +569,6 @@ Global
575569
{FE71504E-C32B-4E2F-9830-21ED448DABC4} = {CA5046EC-C894-4535-8190-A31F75FDEB96}
576570
{62C86664-49F4-4C59-A2EC-1D70D85149D9} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
577571
{1DA2B6AD-F71A-4224-92EB-3D0EE6E68BF4} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
578-
{70E581C3-38BB-46CC-9063-ADF9F2B76570} = {85AFD7F1-6943-40FE-B8EC-AA9DBB42CCA6}
579572
{849357D0-85B3-4326-9D42-AD5A09E9613C} = {B3714D90-F595-4644-8018-ADE19D66B853}
580573
{59588FC9-0A4F-4903-84B0-A2CB2EE6F9AC} = {B3714D90-F595-4644-8018-ADE19D66B853}
581574
{524AE4A6-A15F-466C-AED3-CDF3209E4394} = {1AD64707-0BE0-48B0-A803-916FF96DCB4F}

0 commit comments

Comments
 (0)