CD.GenericRepository 3.0.0-preview.1

This is a prerelease version of CD.GenericRepository.
dotnet add package CD.GenericRepository --version 3.0.0-preview.1
                    
NuGet\Install-Package CD.GenericRepository -Version 3.0.0-preview.1
                    
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="CD.GenericRepository" Version="3.0.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CD.GenericRepository" Version="3.0.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="CD.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 CD.GenericRepository --version 3.0.0-preview.1
                    
#r "nuget: CD.GenericRepository, 3.0.0-preview.1"
                    
#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 CD.GenericRepository@3.0.0-preview.1
                    
#: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=CD.GenericRepository&version=3.0.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CD.GenericRepository&version=3.0.0-preview.1&prerelease
                    
Install as a Cake Tool

CD.GenericRepository

Modern repository and unit-of-work APIs for Entity Framework Core. Installing this package also installs CD.Results, providing both persistence and Result patterns through one package reference.

Install

dotnet add package CD.GenericRepository --prerelease

Create a repository

public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
    : DbContext(options);

public interface IUserRepository : IRepository<User>;

public sealed class UserRepository(AppDbContext context)
    : Repository<User, AppDbContext>(context), IUserRepository;

builder.Services.AddGenericRepositories<AppDbContext>();

Read data

User? user = await repository.GetAsync(
    candidate => candidate.Id == id,
    cancellationToken: cancellationToken);

IReadOnlyList<User> activeUsers = await repository.ListAsync(
    candidate => candidate.IsActive,
    cancellationToken: cancellationToken);

IQueryable<User> query = repository.Query()
    .Where(candidate => candidate.CreatedAt >= startDate)
    .OrderBy(candidate => candidate.Name);

Project only the required columns and return an ordered page:

PagedList<UserSummary> page = await repository.PageAsync(
    user => new UserSummary(user.Id, user.Name),
    user => user.Name,
    pageNumber: 1,
    pageSize: 20,
    predicate: user => user.IsActive,
    cancellationToken: cancellationToken);

Queries are no-tracking by default. Pass asTracking: true when tracked entities are required.

Write data

await repository.AddAsync(user, cancellationToken);
await unitOfWork.SaveChangesAsync(cancellationToken);

bool removed = await repository.RemoveByIdAsync(userId, cancellationToken);
if (removed)
{
    await unitOfWork.SaveChangesAsync(cancellationToken);
}

Transactions

await transactionalUnitOfWork.ExecuteInTransactionAsync(async token =>
{
    await userRepository.AddAsync(user, token);
    await auditRepository.AddAsync(auditEntry, token);
});

Successful operations are saved and committed once. Exceptions roll the transaction back and remain visible to the caller.

Target frameworks

  • net8.0 / EF Core 8.0.30+
  • net9.0 / EF Core 9.0.19+
  • net10.0 / EF Core 10.0.11+

The previous 2.x members remain available with deprecation warnings to support incremental migration.

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.  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 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 (1)

Showing the top 1 NuGet packages that depend on CD.GenericRepository:

Package Downloads
CD.Generic.Repository

Compatibility package for CD.Generic.Repository 2.x users. Migrate to CD.GenericRepository.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-preview.1 56 8/22/2026