Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications
1.0.0-preview.5
dotnet add package Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications --version 1.0.0-preview.5
NuGet\Install-Package Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications -Version 1.0.0-preview.5
<PackageReference Include="Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications" Version="1.0.0-preview.5" />
<PackageVersion Include="Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications" Version="1.0.0-preview.5" />
<PackageReference Include="Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications" />
paket add Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications --version 1.0.0-preview.5
#r "nuget: Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications, 1.0.0-preview.5"
#:package Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications@1.0.0-preview.5
#addin nuget:?package=Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications&version=1.0.0-preview.5&prerelease
#tool nuget:?package=Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications&version=1.0.0-preview.5&prerelease
Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications
A .NET library providing a foundational implementation of the Specification pattern for Entity Framework Core. It enables flexible, reusable, and composable queries using specifications, supporting advanced filtering, dynamic ordering, projections, and pagination.
Features
- Specification pattern for EF Core
- Generic repository base with async methods
- Dynamic ordering by property path (string)
- Projections and advanced query composition
- Paging, includes, and split queries support
Installation
Add the NuGet package to your project:
dotnet add package Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications
Getting Started
1. Create a Specification
Define a specification by inheriting from Specification<TEntity>
:
using Tolitech.Specifications;
public class ActiveCustomersSpecification : Specification<Customer>
{
public ActiveCustomersSpecification()
{
Where(c => c.IsActive);
OrderBy(c => c.Name);
Take(10); // Paging example
}
}
2. Use the Repository
Inherit from the provided Repository<TEntity>
base class:
using Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications;
public class CustomerRepository : Repository<Customer>
{
public CustomerRepository(MyDbContext dbContext) : base(dbContext) { }
}
3. Query with Specifications
var spec = new ActiveCustomersSpecification();
var customers = await customerRepository.ToListAsync(spec, cancellationToken);
4. Projections and Dynamic Ordering
// Projection
var names = await customerRepository.ToListAsync(
spec,
c => c.Name,
cancellationToken);
// Dynamic ordering by string
spec.OrderByAsString.Add("Name:DESC");
5. Advanced: Includes, Paging, Split Queries
public class CustomerWithOrdersSpecification : Specification<Customer>
{
public CustomerWithOrdersSpecification()
{
Where(c => c.IsActive);
Include(c => c.Orders);
EnableSplitQuery();
Skip(10);
Take(10);
}
}
Tolitech.Infrastructure.Persistence.EntityFrameworkCore.Specifications brings powerful, maintainable, and reusable querying to your EF Core repositories.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Tolitech.Domain.Specifications (>= 1.0.0-preview.7)
- Tolitech.Infrastructure.Persistence.EntityFrameworkCore (>= 1.0.0-preview.10)
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 |
---|---|---|
1.0.0-preview.5 | 138 | 8/4/2025 |
1.0.0-preview.4 | 435 | 7/21/2025 |
1.0.0-preview.3 | 114 | 7/3/2025 |
1.0.0-preview.2 | 115 | 7/3/2025 |
1.0.0-preview.1 | 81 | 1/6/2025 |