Pozitron.QuerySpecification 10.2.0

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

// Install Pozitron.QuerySpecification as a Cake Tool
#tool nuget:?package=Pozitron.QuerySpecification&version=10.2.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.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pozitron.QuerySpecification:

Package Downloads
Pozitron.QuerySpecification.EntityFrameworkCore

EntityFrameworkCore plugin to Pozitron.QuerySpecification containing EF evaluators.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.0.0 86 11/8/2024
11.0.0-beta1 81 11/5/2024
10.2.1 96 10/25/2024
10.2.0 1,064 10/12/2024
10.1.0 199 9/29/2024
10.0.0 129 9/18/2024

v10.2.0
     - Added ability to override the specification validator and in-memory evaluator.
     - Performance improvements for in-memory Like.
     - Refactored repositories
       - Removed projection methods from RepositoryBase and IReadRepositoryBase
       - Added IProjectionRepository contract defining the ProjectTo APIs.
       - Added RepositoryWithMapper. It inherits RepositoryBase and implements IProjectionRepository.

     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.