DKNet.EfCore.Repos
9.0.5
See the version list below for details.
dotnet add package DKNet.EfCore.Repos --version 9.0.5
NuGet\Install-Package DKNet.EfCore.Repos -Version 9.0.5
<PackageReference Include="DKNet.EfCore.Repos" Version="9.0.5" />
<PackageVersion Include="DKNet.EfCore.Repos" Version="9.0.5" />
<PackageReference Include="DKNet.EfCore.Repos" />
paket add DKNet.EfCore.Repos --version 9.0.5
#r "nuget: DKNet.EfCore.Repos, 9.0.5"
#:package DKNet.EfCore.Repos@9.0.5
#addin nuget:?package=DKNet.EfCore.Repos&version=9.0.5
#tool nuget:?package=DKNet.EfCore.Repos&version=9.0.5
DKNet.EfCore.Repos
A collection of repository patterns built on Entity Framework Core (EF Core) designed to simplify data access and business logic separation.
Overview
DKNet.EfCore.Repos provides a set of reusable repository classes that encapsulate common data access operations. This allows developers to focus on business logic while maintaining consistent and efficient database interactions.
Features
Generic Repository Base Class: A base class for implementing custom repositories, providing core CRUD (Create, Read, Update, Delete) operations.
Custom Repositories: Pre-built repository classes tailored for specific entity types, offering additional functionality beyond the basic CRUD operations.
Unit Of Work Pattern Support: Integrates seamlessly with the Unit of Work pattern to manage transactions and batch operations efficiently.
Query Customization: Extends EF Core's query capabilities, allowing developers to filter, sort, and paginate data with ease.
Getting Started
Installation
To integrate DKNet.EfCore.Repos into your project, install the NuGet package:
dotnet add package DKNet.EfCore.Repos --version 1.0.0-alpha
Replace --version 1.0.0-alpha
with the appropriate version number when available.
Basic Usage
Here's a simple example of how to use the repository classes in your EF Core application:
public class Program
{
public static void Main()
{
var optionsBuilder = new DbContextOptionsBuilder<YourDbContext>();
// Add repositories to the context configuration
RepositoriesConfiguration.AddRepositories(optionsBuilder);
var dbContext = new YourDbContext(optionsBuilder.Options);
// Use the repository as needed
var userRepository = dbContext.GetService<IRepository<User>>();
var user = await userRepository.GetByIdAsync(1);
...
}
}
Detailed Features
Generic Repository Base Class
The GenericRepository
class provides essential CRUD operations and can be extended to add custom functionality.
Example:
public interface IRepository<T> where T : class
{
Task<T> GetByIdAsync(int id);
Task<List<T>> GetAllAsync();
// Additional methods as needed
}
public class UserRepository : GenericRepository<User>, IUserRepository
{
public async Task<User> GetByEmailAsync(string email)
{
return await base.GetAll()
.FirstOrDefaultAsync(u => u.Email == email);
}
}
Custom Repositories
These are tailored for specific entity types, offering specialized functionality.
Example:
public interface IProductRepository : IRepository<Product>
{
Task<List<Product>> GetProductsByCategoryAsync(string category);
}
public class ProductRepository : GenericRepository<Product>, IProductRepository
{
public async Task<List<Product>> GetProductsByCategoryAsync(string category)
{
return await base.GetAll()
.Where(p => p.Category == category)
.ToListAsync();
}
}
Unit Of Work Pattern Support
The repository classes integrate with the Unit of Work pattern to manage transactions and batch operations.
Example:
public interface IUnitOfWork : IDisposable
{
IRepository<User> Users { get; }
IRepository<Product> Products { get; }
Task<int> SaveChangesAsync();
}
public class EfCoreUnitOfWork<TContext> : IUnitOfWork where TContext : DbContext
{
private readonly TContext _context;
public EfCoreUnitOfWork(TContext context)
{
_context = context;
}
public IRepository<User> Users => new UserRepository(_context);
public IRepository<Product> Products => new ProductRepository(_context);
public async Task<int> SaveChangesAsync()
{
return await _context.SaveChangesAsync();
}
}
Query Customization
The repository classes allow for flexible and powerful querying.
Example:
public interface IProductRepository : IRepository<Product>
{
Task<List<Product>> GetAllPagedAsync(int pageIndex, int pageSize);
}
public class ProductRepository : GenericRepository<Product>, IProductRepository
{
public async Task<List<Product>>> GetAllPagedAsync(int pageIndex, int pageSize)
{
return await base.GetAll()
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
}
}
Contributing
Contributions are welcome and encouraged! If you'd like to contribute to the project, please follow these steps:
- Fork the repository: Create your own copy of the project on GitHub.
- Create a feature branch: Develop new features or bug fixes in a dedicated branch.
- Commit changes: Keep your commits clear and descriptive.
- Push to the branch: Share your changes with the remote repository.
- Create a Pull Request: Submit your changes for review and merging.
License
This project is licensed under MIT License.
Acknowledgments
- Thanks to the Entity Framework Core team for providing a robust framework.
- Special thanks to contributors who have enhanced this library.
Product | Versions 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. |
-
net9.0
- DKNet.EfCore.Extensions (>= 9.0.5)
- DKNet.EfCore.Repos.Abstractions (>= 9.0.5)
- Mapster (>= 7.4.0)
- Meziantou.Analyzer (>= 2.0.202)
- X.PagedList.EF (>= 10.5.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DKNet.EfCore.Repos:
Package | Downloads |
---|---|
DKNet.SlimBus.Extensions
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
9.0.20 | 124 | 7/15/2025 |
9.0.19 | 138 | 7/14/2025 |
9.0.18 | 138 | 7/14/2025 |
9.0.17 | 139 | 7/14/2025 |
9.0.16 | 117 | 7/11/2025 |
9.0.15 | 119 | 7/11/2025 |
9.0.14 | 121 | 7/11/2025 |
9.0.13 | 128 | 7/11/2025 |
9.0.12 | 147 | 7/8/2025 |
9.0.11 | 144 | 7/8/2025 |
9.0.10 | 137 | 7/7/2025 |
9.0.9 | 144 | 7/2/2025 |
9.0.8 | 139 | 7/2/2025 |
9.0.7 | 143 | 7/1/2025 |
9.0.6 | 141 | 6/30/2025 |
9.0.5 | 146 | 6/24/2025 |
9.0.4 | 142 | 6/24/2025 |
9.0.3 | 150 | 6/23/2025 |
9.0.2 | 143 | 6/23/2025 |
9.0.1 | 147 | 6/23/2025 |