Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tanvirarjel/efcore.genericrepository
This repository contains Generic Repository implementation for Entity Framework Core
https://github.com/tanvirarjel/efcore.genericrepository
csharp database dotnet-core entity-framework-core genericrepository repository
Last synced: 1 day ago
JSON representation
This repository contains Generic Repository implementation for Entity Framework Core
- Host: GitHub
- URL: https://github.com/tanvirarjel/efcore.genericrepository
- Owner: TanvirArjel
- License: mit
- Created: 2020-03-26T14:32:45.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-28T14:06:41.000Z (about 2 months ago)
- Last Synced: 2024-11-06T23:47:15.472Z (7 days ago)
- Topics: csharp, database, dotnet-core, entity-framework-core, genericrepository, repository
- Language: C#
- Homepage:
- Size: 1.41 MB
- Stars: 599
- Watchers: 18
- Forks: 89
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```C#
PaginationSpecification specification = new PaginationSpecification();
specification.Conditions.Add(e => e.Name.Contains("Ta"));
specification.PageIndex = 1;
specification.PageSize = 10;PaginatedList paginatedList = await _repository.GetListAsync(specification, e => new EmployeeDto
{
Id = e.Id
Name = e.Name,
DepartmentName = e.DepartmentName
});
```### Free raw SQL support:
```C#
List search = new List() { "Tanvir", "Software" };
string sqlQuery = "Select EmployeeName, DepartmentName from Employee Where EmployeeName LIKE @p0 + '%' and DepartmentName LIKE @p1 + '%'";
List items = await _repository.GetFromRawSqlAsync(sqlQuery, search);```
## βοΈ This library includes following notable features:
1. 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.
2. Itβs providing the Generic Repository with database transaction support.
3. It has all the required methods to query your data in whatever way you want without getting IQueryable from the repository.
4. It also has **`Specification`** pattern support so that you can build your query dynamically i.e. differed query building.
5. It also has database level projection support for your query.
6. It also has support to run raw SQL command against your relational database.
7. It also has support to choose whether you would like to track your query entity/entities or not.
8. It also has support to reset your EF Core DbContext state whenever you really needed.
9. Most importantly, it has full Unit Testing support.
11. Pagination support.
13. 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 `TanvirArjel.EFCore.GenericRepository` [nuget](https://www.nuget.org/packages/TanvirArjel.EFCore.GenericRepository) package into your project as follows:**Package Manager Console:**
```C#
Install-Package TanvirArjel.EFCore.GenericRepository
```
**.NET CLI:**```C#
dotnet add package TanvirArjel.EFCore.GenericRepository
```
Then in the `ConfigureServices` method of the `Startup` class:```C#
public void ConfigureServices(IServiceCollection services)
{
// For single DbContext
services.AddGenericRepository();
// If multiple DbContext
services.AddGenericRepository();
services.AddGenericRepository();
}
```### For query version only:
First install the latest version of `TanvirArjel.EFCore.QueryRepository` [nuget](https://www.nuget.org/packages/TanvirArjel.EFCore.QueryRepository) package into your project as follows:**Package Manager Console:**
```C#
Install-Package TanvirArjel.EFCore.QueryRepository
```
**.NET CLI:**```C#
dotnet add package TanvirArjel.EFCore.QueryRepository
```
Then in the `ConfigureServices` method of the `Startup` class:```C#
public void ConfigureServices(IServiceCollection services)
{
// For single DbContext
services.AddQueryRepository();
// For multiple DbContext
services.AddQueryRepository();
services.AddQueryRepository();
}
```
## π οΈ Usage: Query```C#
public class EmployeeService
{
// For query version, please use `IQueryRepository` instead of `IRepository`
private readonly IRepository _repository; // If single DbContext
private readonly IRepository _dbContext1Repository; // If multiple DbContextpublic EmployeeService(IRepository repository, IRepository dbContext1Repository)
{
_repository = repository;
_dbContext1Repository = dbContext1Repository;
}public async Task GetEmployeeAsync(int employeeId)
{
Employee employee = await _repository.GetByIdAsync(employeeId);
return employee;
}
}
```
## π οΈ Usage: Command```C#
public class EmployeeService
{
private readonly IRepository _repository; // If single DbContext
private readonly IRepository _dbContext1Repository; // If multiple DbContextpublic EmployeeService(IRepository repository, IRepository dbContext1Repository)
{
_repository = repository;
_dbContext1Repository = dbContext1Repository;
}public async Task CreateAsync(Employee employee)
{
await _repository.AddAsync(employee);
await _repository.SaveChangesAsync();return employee.Id;
}
}
```
### For more detail documentation, please visit [Documentation Wiki](https://github.com/TanvirArjel/EFCore.GenericRepository/wiki)