Pozitron.QuerySpecification
10.2.0
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
<PackageReference Include="Pozitron.QuerySpecification" Version="10.2.0" />
paket add Pozitron.QuerySpecification --version 10.2.0
#r "nuget: Pozitron.QuerySpecification, 10.2.0"
// 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.
- Pozitron.QuerySpecification A base package containing the core functionality, in-memory evaluators, and validators.
- Pozitron.QuerySpecification.EntityFrameworkCore
An
EntityFramework Core
plugin to the base package. It contains EF specific evaluators.
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 | 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
- 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.
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.