Hazelnut.EFCore.GenericRepository
1.0.1
dotnet add package Hazelnut.EFCore.GenericRepository --version 1.0.1
NuGet\Install-Package Hazelnut.EFCore.GenericRepository -Version 1.0.1
<PackageReference Include="Hazelnut.EFCore.GenericRepository" Version="1.0.1" />
<PackageVersion Include="Hazelnut.EFCore.GenericRepository" Version="1.0.1" />
<PackageReference Include="Hazelnut.EFCore.GenericRepository" />
paket add Hazelnut.EFCore.GenericRepository --version 1.0.1
#r "nuget: Hazelnut.EFCore.GenericRepository, 1.0.1"
#addin nuget:?package=Hazelnut.EFCore.GenericRepository&version=1.0.1
#tool nuget:?package=Hazelnut.EFCore.GenericRepository&version=1.0.1
EF Core Generic Repository
This library is a Generic Repository implementation for EF Core ORM which will remove developers' pain to write repository layer for each .NET Core and .NET project.
⭐ Giving a star
If you find this library useful, please don't forget to encourage me to do such more stuffs by giving a star to this repository. Thank you.
🔥 What's new
Pagination Support:
PaginationSpecification<Employee> specification = new PaginationSpecification<Employee>();
specification.Conditions.Add(e => e.Name.Contains("Ta"));
specification.PageIndex = 1;
specification.PageSize = 10;
PaginatedList<EmployeeDto> paginatedList = await _repository.GetListAsync(specification, e => new EmployeeDto
{
Id = e.Id
Name = e.Name,
DepartmentName = e.DepartmentName
});
Free raw SQL support:
List<string> search = new List<string>() { "Aitron", "Software" };
string sqlQuery = "Select EmployeeName, DepartmentName from Employee Where EmployeeName LIKE @p0 + '%' and DepartmentName LIKE @p1 + '%'";
List<EmployeeDto> items = await _repository.GetFromRawSqlAsync<EmployeeDto>(sqlQuery, search);
⚙️ This library includes following notable features:
This library can be run on any .NET Core or .NET application which has .NET Core 3.1, .NET Standard 2.1 and .NET 5.0+ support.
It’s providing the Generic Repository with database transaction support.
It has all the required methods to query your data in whatever way you want without getting IQueryable<T> from the repository.
It also has
Specification<T>
pattern support so that you can build your query dynamically i.e. differed query building.It also has database level projection support for your query.
It also has support to run raw SQL command against your relational database.
It also has support to choose whether you would like to track your query entity/entities or not.
It also has support to reset your EF Core DbContext state whenever you really needed.
Most importantly, it has full Unit Testing support.
Pagination support.
Free raw SQL query support both for complex type and primitive types.
✈️ How do I get started?
For full version (both query and command support):
First install the latest version of Hazelnut.EFCore.GenericRepository
nuget package into your project as follows:
Package Manager Console:
Install-Package Hazelnut.EFCore.GenericRepository
.NET CLI:
dotnet add package Hazelnut.EFCore.GenericRepository
Then in the ConfigureServices
method of the Startup
class:
public void ConfigureServices(IServiceCollection services)
{
// For single DbContext
services.AddGenericRepository<YourDbContext>();
// If multiple DbContext
services.AddGenericRepository<YourDbContext1>();
services.AddGenericRepository<YourDbContext2>();
}
For query version only:
First install the latest version of Hazelnut.EFCore.QueryRepository
nuget package into your project as follows:
Package Manager Console:
Install-Package Hazelnut.EFCore.QueryRepository
.NET CLI:
dotnet add package Hazelnut.EFCore.QueryRepository
Then in the ConfigureServices
method of the Startup
class:
public void ConfigureServices(IServiceCollection services)
{
// For single DbContext
services.AddQueryRepository<YourDbContext>();
// For multiple DbContext
services.AddQueryRepository<YourDbContext1>();
services.AddQueryRepository<YourDbContext2>();
}
🛠️ Usage: Query
public class EmployeeService
{
// For query version, please use `IQueryRepository` instead of `IRepository`
private readonly IRepository _repository; // If single DbContext
private readonly IRepository<YourDbContext1> _dbContext1Repository; // If multiple DbContext
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbContext1Repository)
{
_repository = repository;
_dbContext1Repository = dbContext1Repository;
}
public async Task<Employee> GetEmployeeAsync(int employeeId)
{
Employee employee = await _repository.GetByIdAsync<Employee>(employeeId);
return employee;
}
}
🛠️ Usage: Command
public class EmployeeService
{
private readonly IRepository _repository; // If single DbContext
private readonly IRepository<YourDbContext1> _dbContext1Repository; // If multiple DbContext
public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbContext1Repository)
{
_repository = repository;
_dbContext1Repository = dbContext1Repository;
}
public async Task<int> CreateAsync(Employee employee)
{
await _repository.AddAsync(employee);
await _repository.SaveChangesAsync();
return employee.Id;
}
}
For more detail documentation, please visit Documentation Wiki
Product | Versions 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 was computed. 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. |
-
net8.0
- Hazelnut.EFCore.QueryRepository (>= 1.0.1)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.16)
- System.Linq.Dynamic.Core (>= 1.6.4)
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 |
---|---|---|
1.0.1 | 99 | 5/22/2025 |
1. dotNET 8.0 support has been added.
2. ExecuteUpdateAsync and ExecuteDeleteAsync have been added.