Carubbi.GenericRepository
2.0.0
dotnet add package Carubbi.GenericRepository --version 2.0.0
NuGet\Install-Package Carubbi.GenericRepository -Version 2.0.0
<PackageReference Include="Carubbi.GenericRepository" Version="2.0.0" />
<PackageVersion Include="Carubbi.GenericRepository" Version="2.0.0" />
<PackageReference Include="Carubbi.GenericRepository" />
paket add Carubbi.GenericRepository --version 2.0.0
#r "nuget: Carubbi.GenericRepository, 2.0.0"
#:package Carubbi.GenericRepository@2.0.0
#addin nuget:?package=Carubbi.GenericRepository&version=2.0.0
#tool nuget:?package=Carubbi.GenericRepository&version=2.0.0
Carubbi.GenericRepository
A generic repository pattern library for .NET with server-side paging, filtering, sorting and eager loading over Entity Framework Core.
Features
- Composable search queries: filters (ANDed), multi-level sorting and paging in a single call.
- Dynamic sorting by property path strings — including nested paths like
Address.City— built on expression trees, with optionalASC/DESCsuffixes. - Eager loading via comma-separated navigation paths (
"Orders, Address"). - Paged results carrying total count plus
HasNext/HasPreviousflags. - Works against an EF Core
DbContextor any arbitraryIQueryable<T>source.
Installation
dotnet add package Carubbi.GenericRepository
Usage
using Carubbi.GenericRepository;
// Your DbContext implements IDbContext by exposing Set<TEntity>()
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options), IDbContext
{
public DbSet<Customer> Customers => Set<Customer>();
}
var repository = new GenericRepository<Customer>(dbContext);
var query = new SearchQuery<Customer>
{
Skip = 20,
Take = 10,
IncludeProperties = "Orders",
};
query.AddFilter(c => c.Age >= 18);
query.AddSortCriteria(new DynamicFieldSortCriteria<Customer>("Address.City"));
query.AddSortCriteria(new DynamicFieldSortCriteria<Customer>("Name DESC"));
PagedListResult<Customer> page = repository.Search(query);
// page.Entities -> current page rows
// page.Count -> total rows across all pages
// page.HasNext -> more pages available?
// page.HasPrevious
You can also point the repository at any in-memory or external sequence:
var repository = new GenericRepository<Customer>(dbContext, customers.AsQueryable());
Building and testing
Requires the .NET 10 SDK. Integration tests additionally require a running Docker engine (they start a SQL Server 2022 container automatically; without Docker they are skipped).
dotnet build -c Release
dotnet test --solution Carubbi.GenericRepository.sln -c Release
Unit tests only:
dotnet test Carubbi.GenericRepository.Tests -c Release
Publishing
The publish workflow runs on tags matching v* (and manual dispatch). It packs the library in Release mode and pushes it to nuget.org using Trusted Publishing. To release:
git tag v2.0.0
git push origin v2.0.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.