Pozitron.QuerySpecification.EntityFrameworkCore 10.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pozitron.QuerySpecification.EntityFrameworkCore --version 10.1.0                
NuGet\Install-Package Pozitron.QuerySpecification.EntityFrameworkCore -Version 10.1.0                
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="Pozitron.QuerySpecification.EntityFrameworkCore" Version="10.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pozitron.QuerySpecification.EntityFrameworkCore --version 10.1.0                
#r "nuget: Pozitron.QuerySpecification.EntityFrameworkCore, 10.1.0"                
#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 Pozitron.QuerySpecification.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Pozitron.QuerySpecification.EntityFrameworkCore&version=10.1.0

// Install Pozitron.QuerySpecification.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Pozitron.QuerySpecification.EntityFrameworkCore&version=10.1.0                

A .NET library for building query specifications.

Usage

Create your specification classes by inheriting from the Specification<T> class, and use the builder Query to build your queries in the constructor.

public class CustomerSpec : Specification<Customer>
{
  public CustomerSpec(int age, string nameTerm)
  {
    Query
      .Where(x => x.Age > age)
      .Like(x => x.Name, $"%{nameTerm}%")
      .Include(x => x.Addresses)
          .ThenInclude(x => x.Contact)
      .OrderBy(x => x.Id)
          .ThenBy(x => x.Name)
      .Skip(10)
      .Take(10)
      .AsSplitQuery();
  }
}

Apply the specification to DbSet<T> or to any IQueryable<T> source.

var spec = new CustomerSpec(30, "John");

List<Customer> result = await _context
    .Customers
    .WithSpecification(spec)
    .ToListAsync();

Projections

The specification can be used to project the result into a different type. Inherit from Specification<T, TResult> class, where TResult is the type you want to project into. This offers strongly typed experience in the builder and during the evaluation.

public class CustomerDtoSpec : Specification<Customer, CustomerDto>
{
  public CustomerDtoSpec(int age, string nameTerm)
  {
    Query
      .Where(x => x.Age > age)
      .Like(x => x.Name, $"%{nameTerm}%")
      .OrderBy(x => x.Name)
      .Select(x => new CustomerDto(x.Id, x.Name));
  }
}

Apply the specification to DbSet<T> or any IQueryable<T> source.

var spec = new CustomerSpec(30, "John");

List<CustomerDto> result = await _context
    .Customers
    .WithSpecification(spec)
    .ToListAsync();

Give a Star! ⭐

If you like or are using this project please give it a star. Thanks!

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.0.0 79 11/8/2024
11.0.0-beta1 60 11/5/2024
10.2.1 88 10/25/2024
10.2.0 1,059 10/12/2024
10.1.0 176 9/29/2024
10.0.0 106 9/18/2024

v10.1.0
     - Publish a separate symbol package (snupkg).
     - Added ToPagedResult extensions.
     - Consolidated method and parameter names for evaluator APIs.
     - IEvaluator.GetQuery renamed to IEvaluator.Evaluate
     - Refactored pagination infrastructure
       - Removed PaginationEvaluator
       - Apply pagination at the end of the query (fixed SelectMany issues).
       - PagedResponse renamed to PagedResult
       - Pagination.Default renamed to Pagination.Empty

     v10.0.0
     - Dropped support for old TFMs. Support only .NET 8.
     - Dropped support for old plugin packages. Support only EntityFrameworkCore 8.
     - Redesigned the infrastructure and refactored the internals.
     - Removed all specification interfaces.
     - Minimized the memory footprint.
     - Removed obsolete features.
     - Improved query-building capabilities.
     - Added full support for pagination.
     - Added support for paginated responses.
     - Added arbitrary projection capabilities in repositories.