DotNetToolbox.Linq 8.1.1

dotnet add package DotNetToolbox.Linq --version 8.1.1                
NuGet\Install-Package DotNetToolbox.Linq -Version 8.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetToolbox.Linq" Version="8.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetToolbox.Linq --version 8.1.1                
#r "nuget: DotNetToolbox.Linq, 8.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 queryables
  • AsyncQueryable<T>: Base implementation of IAsyncQueryable
  • EmptyAsyncQueryable<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 sequence
  • ForEach: Allows iteration over query results
  • ToIndexedList: Creates a list of indexed items
  • ToArray/ToList/ToHashSet with custom projections

ExpressionExtensions

  • ReplaceExpressionType: Allows type-safe modification of LINQ expressions
  • Apply: 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
8.1.1 134 8/24/2024
8.1.0 115 5/21/2024

DotNetToolbox.Linq Version 8.1.1

     Stable release of the DotNetToolbox.Linq library.