• Stars
    star
    594
  • Rank 75,329 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This repository contains Generic Repository implementation for Entity Framework Core

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 encouraging 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>() { "Tanvir", "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:

  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<T> 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.

  10. Pagination support.

  11. 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 package into your project as follows:

Package Manager Console:

Install-Package TanvirArjel.EFCore.GenericRepository

.NET CLI:

dotnet add package TanvirArjel.EFCore.GenericRepository

Then in the ConfirugeServices 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 TanvirArjel.EFCore.QueryRepository nuget package into your project as follows:

Package Manager Console:

Install-Package TanvirArjel.EFCore.QueryRepository

.NET CLI:

dotnet add package TanvirArjel.EFCore.QueryRepository

Then in the ConfirugeServices 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> _dbConext1Repository; // If multiple DbContext

    public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbConext1Repository)
    {
        _repository = repository;
        _dbConext1Repository = dbConext1Repository;
    }

    public async Task<Employee> GetEmployeeAsync(int employeeId)
    {
        Employee employee = await _repository.GetByIdAsync<Employee>(1);
        return employee;
    }
}

๐Ÿ› ๏ธ Usage: Command

public class EmployeeService
{
    private readonly IRepository _repository; // If single DbContext
    private readonly IRepository<YourDbContext1> _dbConext1Repository; // If multiple DbContext

    public EmployeeService(IRepository repository, IRepository<YourDbContext1> dbConext1Repository)
    {
        _repository = repository;
        _dbConext1Repository = dbConext1Repository;
    }

    public async Task<int> CreateAsync(Employee employee)
    {
        await _repository.AddAsync(employee);
        await _repository.SaveChangesAsync();

        return employee.Id;
    }
}

For more detail documentaion, please visit Documentation Wiki

More Repositories

1

CleanArchitecture

This repository contains the implementation of domain-driven design and clear architecture in ASP.NET Core.
C#
381
star
2

SolidPrinciples

Contains clear examples and explanations of SOLID design principles.
C#
109
star
3

TanvirArjel.Extensions.Microsoft.DependencyInjection

This repository contains the generic service registration in ASP.NET Core Dependency Injection Container.
C#
55
star
4

CustomValidation

This is a custom validation library for C# .NET projects.
C#
40
star
5

AspNetCoreMvcIdentity

ASP.NET Core identity has been implemented as MVC for version greater than 2.0
C#
28
star
6

TanvirArjel.Blazor

This library is an extension of Microsoft ASP.NET Core Blazor
C#
15
star
7

LearningDSA

This repository contains implementation of relevant algorithms of different data structure. More importantly, this repository will be updated on continuous basis.
C++
10
star
8

TanvirArjel.Extensions.Microsoft.Caching

This library extended the functionality of IDistributedCache interface to make the caching mechanism more easier.
C#
6
star
9

SpringBootApi

This repository contains sample REST API implementation with Java Spring Boot.
Java
5
star
10

ArgumentChecker

This is method's arguments checking library in C#.
C#
4
star
11

JwtAuthenticationInAspNetCore

C#
4
star
12

CheckBoxListInAspNetMVC

Handling CheckBox List In ASP.NET MVC is somewhat complicated for those who are very new with development in ASP.NET MVC. Here I have shown the very simplest and easiest way to handling checkboxlist in ASP.NET MVC
C#
4
star
13

AspNetCore.ExceptionLogger

This is a global exception handler library for ASP.NET Core projects.
C#
4
star
14

DjangoCrud

This is a simple full fledged crud application with one model
Python
3
star
15

SimpleUniversityManagementAppCore

C#
2
star
16

JqueryDataTablesWithPopupInputForm

JavaScript
2
star
17

CustomActionBasedAuthenticationInASPNetMVC

JavaScript
2
star
18

CqrsWithMediatR

This is a sample project for the implementation of CQRS with MediatR
C#
2
star
19

LoggingWithSerilogInAspNetCore

This is a sample application demonstrating the logging functionality in asp.net core with serilog
HTML
2
star
20

CustomRoleBasedAuthenticationInASPNetMVC

JavaScript
2
star
21

MauiDemo

Connection refused when calling ASP.NET Core API endpoints from .NET MAUI Blazor App
C#
2
star
22

AspNetCoreLocalization

This app contain the configuration of how to make an ASP.NET Core application localized.
HTML
2
star
23

KibanaLog

This repository contain implementation of logging to Elastic Search and visualize with Kibana.
C#
2
star
24

WeatherApp

The is a demo weather update app
C#
2
star
25

JqueryDataTableWithAngular

This is Jquery DataTable With Angular
TypeScript
1
star
26

AngularCrudWithAspNetCoreWebApi

CSS
1
star
27

SendingEmailInAspNetMVC

Nothing
C#
1
star
28

DependencyInjectionInAspNetMvc

Described how to implement dependency injection in asp.net mvc
JavaScript
1
star
29

New-features-in-CSharp6.0

New amazing features in C# 6.0 with examples
C#
1
star
30

JQueryDataTableWithAspNetMVC

JavaScript
1
star
31

SimpleAdminTemplate

This is simple admin template for small and medium project
JavaScript
1
star
32

SimlpeLibraryManagementSystem

SimlpeLibraryManagementSystem With ASP.NET MVC, ASP.NET Web API and AngularJS
C#
1
star
33

JQueryDateTimePicker

Simplest Way to Use JQuery Date Picker/Calendar in ASP.NET/ASP.NET MVC
JavaScript
1
star
34

PollyRetryAndCircuitBreaker

The repo contains Polly integration with ASP.NET Core.
C#
1
star
35

tanvirarjel.github.io

Github Pages of Tanvir Arjel
HTML
1
star
36

CustomServerSidePaginationInAspNetMvc

Pagination is a very very important and oblagatory feature to handling the mammoth database in any platform.For them, those who are very new to Asp.net mvc developement, Handling pagination effectively and efficiently is a somewhat complicated suject. Here I have shown how to handle pagination effectively and efficiently incase of a very very large database.
C#
1
star