ClassLibrary.EFCore 1.0.6

dotnet add package ClassLibrary.EFCore --version 1.0.6
NuGet\Install-Package ClassLibrary.EFCore -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ClassLibrary.EFCore" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ClassLibrary.EFCore --version 1.0.6
#r "nuget: ClassLibrary.EFCore, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ClassLibrary.EFCore as a Cake Addin
#addin nuget:?package=ClassLibrary.EFCore&version=1.0.6

// Install ClassLibrary.EFCore as a Cake Tool
#tool nuget:?package=ClassLibrary.EFCore&version=1.0.6

NET8 EFCore Generic Repository

Collection of a generic implementation of Entity Framework Core for .NET 8 mostly used in my private and/or work projects thus avoiding the duplication of repetitive code.

Give a star

If you found this Implementation helpful or used it in your Projects, do give it a ⭐ on Github. Thanks!

Installation

The library is available on NuGet or run the following command in the .NET CLI:

dotnet add package ClassLibrary.EFCore

How to use

Registering services

services.AddDbContext<YourDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<DbContext, YourDbContext>();
services.AddScoped<IRepository<YourEntity, YourTypeEntityId>, Repository<YourEntity, YourTypeEntityId>>();

Alternatively the generic version of the repository can be registered as follows:

services.AddScoped(typeof(IRepository<,>), typeof(Repository<,>));

Example entity

public class YourEntity : IEntity<int>
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

Example interface

public interface IYourEntityService
{
    Task<IEnumerable<YourEntity>> GetAllAsync();
    Task<YourEntity> GetByIdAsync(int id);
    Task CreateAsync(YourEntity entity);
    Task UpdateAsync(YourEntity entity);
    Task DeleteAsync(YourEntity entity);

    //Alternative method for deleting
    Task DeleteByIdAsync(int id);

    //Optional method
    Task<List<PersonEntity>> GetPaginatedAsync(Func<IQueryable<PersonEntity>,
        IIncludableQueryable<PersonEntity, object>> includes,
        Expression<Func<PersonEntity, bool>> conditionWhere,
        Expression<Func<PersonEntity, dynamic>> orderBy,
        string orderType, int pageIndex, int pageSize);
}

Example class

public class YourEntityService : IYourEntityService
{
    private readonly IRepository<YourEntity, int> _repository;

    public YourEntityService(IRepository<YourEntity, int> repository)
    {
        _repository = repository;
    }

    public async Task<IEnumerable<YourEntity>> GetAllAsync()
    {
        return await _repository.GetAllAsync();
    }

    public async Task<YourEntity> GetByIdAsync(int id)
    {
        return await _repository.GetByIdAsync(id);
    }

    public async Task CreateAsync(YourEntity entity)
    {
        await _repository.CreateAsync(entity);
    }

    public async Task UpdateAsync(YourEntity entity)
    {
        await _repository.UpdateAsync(entity);
    }

    public async Task DeleteAsync(YourEntity entity)
    {
        await _repository.DeleteAsync(entity);
    }

    //Alternative method for deleting
    public async Task DeleteByIdAsync(int id)
    {
        await _repository.DeleteByIdAsync(id);
    }

    //Optional method
    public async Task<List<YourEntity>> GetPaginatedAsync(Func<IQueryable<YourEntity>,
        IIncludableQueryable<YourEntity, object>> includes, Expression<Func<YourEntity, bool>> conditionWhere,
        Expression<Func<YourEntity, dynamic>> orderBy, string orderType, int pageIndex, int pageSize)
    {
        return await _repository.GetPaginatedAsync(includes, conditionWhere, orderBy, orderType, pageIndex, pageSize);
    }
}

Contributing

Contributions and/or suggestions are always welcome.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.6 88 4/23/2024
1.0.4 85 4/13/2024
1.0.3 83 3/26/2024
1.0.2 89 3/20/2024
1.0.1 83 3/19/2024