Pozitron.QuerySpecification.EntityFrameworkCore 10.0.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.0.0                
NuGet\Install-Package Pozitron.QuerySpecification.EntityFrameworkCore -Version 10.0.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.0.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.0.0                
#r "nuget: Pozitron.QuerySpecification.EntityFrameworkCore, 10.0.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.0.0

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

<img align="left" src="docs/pozitronlogo.png" width="120" height="120">

  NuGetNuGet

     

A .NET library for building query specifications.

Packages:

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 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 93 11/8/2024
11.0.0-beta1 65 11/5/2024
10.2.1 95 10/25/2024
10.2.0 1,063 10/12/2024
10.1.0 182 9/29/2024
10.0.0 112 9/18/2024

- 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.