EntityFrameworkCore.PersistenceApi 1.3.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package EntityFrameworkCore.PersistenceApi --version 1.3.3                
NuGet\Install-Package EntityFrameworkCore.PersistenceApi -Version 1.3.3                
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="EntityFrameworkCore.PersistenceApi" Version="1.3.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.PersistenceApi --version 1.3.3                
#r "nuget: EntityFrameworkCore.PersistenceApi, 1.3.3"                
#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 EntityFrameworkCore.PersistenceApi as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.PersistenceApi&version=1.3.3

// Install EntityFrameworkCore.PersistenceApi as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.PersistenceApi&version=1.3.3                

Entity Framework Autowired Repository with Unit of Work pattern

Creating a repository interface and implementing a class is a really boring and annoying work. When I saw JpaRepository in Java world, I wondered if there's a similar implmentation of JpaRepository in .NET side. I, however, couldn't find anything. This library will liberate you from this annoying task.

How To Use

1. Your DbContext should have IEpaDbContext and you can define your DbSet property as usual.

public ApplicationDbContext : DbContext, IEpaDbContext
{
    DbSet<Order> Orders { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        ...
    }
}

2. Add the dependency injection in the Program.cs

var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));

// Below dependency injection is required. 
builder.Services.AddScoped<IEpaDbContext, ApplicationDbContext>();
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();

3. Define a interface inheriting IEpaRepository interface.

public interface IOrderRepository : IEpaRepository<Order, Guid>
{
}

4. That's it. No interface implementation. Just get the repository and use it

public class IndexModel : PageModel
{
    private readonly IUnitOfWork _unitOfWork;
    public IReadOnlyCollection<Order> Orders;

    public IndexModel(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task OnGetAsync()
    {
        var orderRepository = _unitOfWork.GetRepository<IOrderRepository>();
        Orders = await orderRepository.GetAsync();
    }
}

Soft-Deleted Entity

As a developer, we often forget to filter out soft deleted entities. In order to avoid the same mistake, I introduced IDeletable interface. When your entity implements IDeletable, UnitOfWork.Queryable will filter out the soft deleted entity automatically.

public class Order : IDeletable
{
    public bool IsDeleted { get; set; } // set true for soft-deleted
    public DateTime? DeletedAt { get; set; }
}
public class IndexModel : PageModel
{
    private readonly IUnitOfWork _unitOfWork;
    public IReadOnlyCollection<Order> Orders;

    public IndexModel(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task OnGetAsync()
    {
        // Queryable filters out the soft-delete entity automatically.
        Orders = _unitOfWork.Queryable<Order>().ToList();
    }
}

Please see the WebApplication project for the demo.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.5.0 207 12/23/2023
1.4.0 249 3/25/2023
1.3.3 222 3/20/2023
1.3.2 226 3/19/2023
1.3.1 214 3/19/2023
1.3.0 220 3/16/2023
1.2.0 230 3/13/2023
1.1.1 237 3/7/2023
1.1.0 223 3/7/2023
1.0.0 259 2/25/2023