The .NET 10 version will change LINQ.
LINQ has served as a core element of .NET development for ten years allowing clear data querying across collections, databases along with other items. But with the .NET 10 release, Microsoft is making a big change that will redefine how developers use LINQ in asynchronous situations.
The Big Change — Native LINQ Support for IAsyncEnumerable
Until now using asynchronous streams in .NET meant depending on the community maintained System.Linq.Async NuGet package. This package gave LINQ-like abilities to IAsyncEnumerable allowing developers to use methods like .SelectAwait(), .WhereAwaitAsync() in addition to .ToListAsync().
What’s New?
.NET 10 provides a new built in AsyncEnumerable class in the BCL (Base Class Library), which offers LINQ support for IAsyncEnumerable, which means that there is no need to install external packages for async LINQ, and there is full equality with synchronous LINQ.
IAsyncEnumerable<MyObject> items = GetItems();
var result = await items
.Where(x => x.IsEnabled)
.Select(x => x.SomeValue)
.ToListAsync();
Code language: JavaScript (javascript)
Important Changes You Should Know
A switch causes a breaking change that is not compatible with some source. If a project refers to System.Linq.Async, it is probable that you will encounter errors because some method names overlap.
For a Migration Strategy
- If you upgrade to .NET 10, remove the
System.Linq.Asyncpackage. - If you need to support .NET 10 and earlier versions, use conditional package references:
<PackageReference Include="System.Linq.Async" Version="6.0.1">
<ExcludeAssets>all</ExcludeAssets>
</PackageReference>
Code language: HTML, XML (xml)
- Replace uses of .SelectAwait() and .WhereAwaitAsync() with their simple counterparts.
Why This Is Important
This change is a strategic move to actually make asynchronous programming in .NET more simple and performant.
There is better discoverability because Async LINQ methods are now a part of the core experience.
There is improved performance because native implementations benefit from runtime optimizations.
For consistency, developers can now use LINQ in a uniform way across sync and async contexts.