diff --git a/entity-framework/core/miscellaneous/async.md b/entity-framework/core/miscellaneous/async.md index 4d7bc65063..75d01c4742 100644 --- a/entity-framework/core/miscellaneous/async.md +++ b/entity-framework/core/miscellaneous/async.md @@ -37,8 +37,20 @@ Note that there are no async versions of some LINQ operators such as to execute the query on the database, and continue composing client-side LINQ operators over the resulting . 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 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 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). diff --git a/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj b/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj deleted file mode 100644 index 7bf753d26b..0000000000 --- a/samples/core/Miscellaneous/AsyncWithSystemInteractive/AsyncWithSystemInteractive.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net8.0 - EFAsyncWithSystemInteractive - EFAsyncWithSystemInteractive - - - - - - - - - diff --git a/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs b/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs deleted file mode 100644 index 4d76d32e21..0000000000 --- a/samples/core/Miscellaneous/AsyncWithSystemInteractive/Program.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; - -namespace EFAsync; - -public class Program -{ - public static async Task Main(string[] args) - { - await using var context = new BloggingContext(); - await context.Database.EnsureDeletedAsync(); - await context.Database.EnsureCreatedAsync(); - - #region SystemInteractiveAsync - var groupedHighlyRatedBlogs = await context.Blogs - .AsQueryable() - .Where(b => b.Rating > 3) // server-evaluated - .AsAsyncEnumerable() - .GroupBy(b => b.Rating) // client-evaluated - .ToListAsync(); - #endregion - } -} - -public class BloggingContext : DbContext -{ - public DbSet Blogs { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFAsync;Trusted_Connection=True;ConnectRetryCount=0"); - } -} - -public class Blog -{ - public int BlogId { get; set; } - public string Url { get; set; } - public int Rating { get; set; } -} diff --git a/samples/core/Samples.sln b/samples/core/Samples.sln index a27ec19a69..1b483456a1 100644 --- a/samples/core/Samples.sln +++ b/samples/core/Samples.sln @@ -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}" @@ -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 @@ -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}