Carubbi.GenericRepository 2.0.0

dotnet add package Carubbi.GenericRepository --version 2.0.0
                    
NuGet\Install-Package Carubbi.GenericRepository -Version 2.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="Carubbi.GenericRepository" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Carubbi.GenericRepository" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Carubbi.GenericRepository" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Carubbi.GenericRepository --version 2.0.0
                    
#r "nuget: Carubbi.GenericRepository, 2.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.
#:package Carubbi.GenericRepository@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Carubbi.GenericRepository&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Carubbi.GenericRepository&version=2.0.0
                    
Install as a Cake Tool

Carubbi.GenericRepository

NuGet CI

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 optional ASC/DESC suffixes.
  • Eager loading via comma-separated navigation paths ("Orders, Address").
  • Paged results carrying total count plus HasNext / HasPrevious flags.
  • Works against an EF Core DbContext or any arbitrary IQueryable<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 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. 
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
2.0.0 88 8/25/2026
1.4.0 1,448 8/21/2018