Entity Framework Core implementation of the generic repository pattern.
- Generic
IRepository<T>implementation for Entity Framework Core - Async/await support with
CancellationToken - Include and ThenInclude for eager loading
- No-tracking queries for read-only scenarios
- Patch operations for partial updates
- Batch operations (AddRange, Update collections)
dotnet add package UkadGroup.EfRepositoryOr via NuGet Package Manager:
Install-Package UkadGroup.EfRepository
- Have your DbContext implement
IEfRepositoryDbContext:
public class AppDbContext : DbContext, IEfRepositoryDbContext
{
public DbSet<Product> Products { get; set; }
}- Register the repository in your DI container:
services.AddDbContext<AppDbContext>();
services.AddScoped<IEfRepositoryDbContext>(sp => sp.GetRequiredService<AppDbContext>());
services.AddEfRepository();- Inject and use the repository:
public class ProductService
{
private readonly IRepository<Product> _repository;
public ProductService(IRepository<Product> repository)
{
_repository = repository;
}
public async Task<Product> GetByIdAsync(int id)
{
return await _repository.GetByIdAsync(id);
}
}- .NET Standard 2.0+
- Entity Framework Core 3.1+
- UkadGroup.IRepository
MIT License - see LICENSE for details.
UKAD provides engineering support for teams that need help with solution design, integration or long term development. If you want to extend this project or need expertise in .NET, React, Azure, AI, Umbraco or Optimizely, you can contact us at hi@ukad-group.com.