DotNetToolbox.Linq
8.1.1
dotnet add package DotNetToolbox.Linq --version 8.1.1
NuGet\Install-Package DotNetToolbox.Linq -Version 8.1.1
<PackageReference Include="DotNetToolbox.Linq" Version="8.1.1" />
paket add DotNetToolbox.Linq --version 8.1.1
#r "nuget: DotNetToolbox.Linq, 8.1.1"
// Install DotNetToolbox.Linq as a Cake Addin #addin nuget:?package=DotNetToolbox.Linq&version=8.1.1 // Install DotNetToolbox.Linq as a Cake Tool #tool nuget:?package=DotNetToolbox.Linq&version=8.1.1
DotNetToolbox.Linq
Introduction
DotNetToolbox.Linq is a powerful C# library for .NET 8, designed to enhance and extend LINQ (Language Integrated Query) capabilities. It provides a suite of utilities and extension methods to simplify complex query operations, improve performance, and add new functionalities to LINQ.
Installation
dotnet add package DotNetToolbox.Linq
Dependencies
- .NET 8
Key Features
AsyncQueryable Extensions
- Provides asynchronous versions of common LINQ operations
- Supports efficient handling of large datasets in asynchronous scenarios
Enhanced Queryable Extensions
- Extends IQueryable with additional methods for advanced querying
- Includes operations like
ToIndexedList
,AsIndexed
, and more
Expression Manipulation
- Utilities for modifying and transforming LINQ expressions
- Includes
ExpressionConversionVisitor
for type-safe expression modifications
Type Mapping
TypeMapper
class for mapping between different types in LINQ expressions
Core Components
AsyncQueryable
IAsyncQueryable<T>
: Interface for asynchronous queryablesAsyncQueryable<T>
: Base implementation of IAsyncQueryableEmptyAsyncQueryable<T>
: Represents an empty async queryable
AsyncQueryableExtensions
Provides asynchronous versions of common LINQ operations, including:
AggregateAsync
AllAsync
AnyAsync
AverageAsync
ContainsAsync
CountAsync
ElementAtAsync
FirstAsync
/FirstOrDefaultAsync
LastAsync
/LastOrDefaultAsync
MaxAsync
/MinAsync
SumAsync
ToArrayAsync
/ToListAsync
/ToDictionaryAsync
/ToHashSetAsync
QueryableExtensions
Extends IQueryable with additional methods:
AsIndexed
: Converts a query to an indexed sequenceForEach
: Allows iteration over query resultsToIndexedList
: Creates a list of indexed itemsToArray
/ToList
/ToHashSet
with custom projections
ExpressionExtensions
ReplaceExpressionType
: Allows type-safe modification of LINQ expressionsApply
: Applies an expression to an enumerable collection
Usage Examples
Using AsyncQueryable
IAsyncQueryable<int> asyncNumbers = AsyncQueryable.Range(1, 100);
var sum = await asyncNumbers.SumAsync();
Asynchronous LINQ Operations
var query = dbContext.Users.Where(u => u.IsActive);
var activeUserCount = await query.CountAsync();
var firstActiveUser = await query.FirstOrDefaultAsync();
Using Indexed Queries
var indexedQuery = dbContext.Products.AsIndexed();
var indexedList = await indexedQuery.ToListAsync();
foreach (var item in indexedList)
{
Console.WriteLine($"Index: {item.Index}, Product: {item.Value.Name}");
}
Expression Type Replacement
Expression<Func<User, bool>> expr = u => u.Age > 18;
var convertedExpr = expr.ReplaceExpressionType(new TypeMapper<User, Customer>(u => new Customer { Age = u.Age }));
Contributing
Contributions to DotNetToolbox.Linq are welcome. Please ensure that your code adheres to the project's coding standards and is covered by unit tests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- DotNetToolbox.Core (>= 8.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DotNetToolbox.Linq:
Package | Downloads |
---|---|
DotNetToolbox.Data
DotNetToolbox.Data: A comprehensive utility library for handling data storage in a agnostic way. |
GitHub repositories
This package is not used by any popular GitHub repositories.
DotNetToolbox.Linq Version 8.1.1
Stable release of the DotNetToolbox.Linq library.