RepositoryKit.EntityFramework 9.0.4

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

<div align="center"> <img src="logo-64x64.png" width="120" alt="RepositoryKit logo" />

RepositoryKit.EntityFramework

Entity Framework Core Implementation for RepositoryKit

</div>


📦 Package

This package contains the Entity Framework Core based implementation of the RepositoryKit abstractions.


✅ Implementations

Class Purpose
EfReadOnlyRepository<TEntity,TContext> Read-only LINQ queries on your entities
EfRepository<TEntity, TContext> Full-featured CRUD repository for EF Core
EfUnitOfWork<TContext> Unit of Work for a single DbContext
EfUnitOfWorkManager Multi-context Unit of Work resolver via DI

🚀 Usage Examples

1. Register in DI (Startup or Program.cs)

// Register DbContext and RepositoryKit services
builder.Services.AddDbContext<SampleDbContext>(opt => opt.UseInMemoryDatabase("SampleDb"));
builder.Services.AddScoped(typeof(IUnitOfWork<>), typeof(EfUnitOfWork<>));
builder.Services.AddSingleton<IUnitOfWorkManager, EfUnitOfWorkManager>();

// Custom repository registration (interface-based)
builder.Services.AddScoped<IProductRepository, ProductRepository>();

2. Basic Repository & UnitOfWork Usage (Minimal API)

app.MapPost("/products", async (IUnitOfWork<SampleDbContext> uow, Product product) =>
{
    var repo = uow.GetRepository<Product>();
    await repo.AddAsync(product);
    await uow.SaveChangesAsync();
    return Results.Created($"/products/{product.Id}", product);
});

3. Custom Repository Inheritance & Usage

Custom Repository Interface and Implementation

public interface IProductRepository : IRepository<Product>
{
    Task<List<Product>> GetExpensiveProductsAsync(decimal minPrice);
}

public class ProductRepository : EfRepository<Product, SampleDbContext>, IProductRepository
{
    public ProductRepository(SampleDbContext context) : base(context) { }

    public async Task<List<Product>> GetExpensiveProductsAsync(decimal minPrice)
    {
        return await _dbSet.Where(p => p.Price > minPrice).ToListAsync();
    }
}
Endpoint Usage
app.MapGet("/products/expensive", async (IProductRepository repo, decimal minPrice) =>
{
    var expensive = await repo.GetExpensiveProductsAsync(minPrice);
    return Results.Ok(expensive);
});

4. Multiple Contexts with IUnitOfWorkManager

app.MapGet("/multi-context-demo", (IUnitOfWorkManager uowManager) =>
{
    var uow = uowManager.GetUnitOfWork<SampleDbContext>();
    var repo = uow.GetRepository<Product>();
    // Use repo as needed...
});

🚨 Exception Handling

All repository and unit of work operations wrap provider or database exceptions with the standard RepositoryException:`

try
{
    await repository.AddAsync(product);
    await unitOfWork.SaveChangesAsync();
}
catch (RepositoryException ex) when (ex.ErrorType == RepositoryErrorType.Add)
{
    // Handle or log rich error info
}

🤝 Dependencies

📜 License

MIT © Ataberk Kaya


📎 This package is the official EF Core provider for RepositoryKit

Product 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. 
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 RepositoryKit.EntityFramework:

Package Downloads
RepositoryKit

Umbrella package for RepositoryKit - a modular repository pattern infrastructure that supports EF Core, MongoDB and clean LINQ extensions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.4 211 6/9/2025
9.0.3 147 6/3/2025
9.0.2 141 6/1/2025

Initial stable version for EF Core repositories using .NET 9 compatible structure.