RA.Utilities.Data.EntityFramework 10.0.0-rc.2

Prefix Reserved
This is a prerelease version of RA.Utilities.Data.EntityFramework.
There is a newer version of this package available.
See the version list below for details.
dotnet add package RA.Utilities.Data.EntityFramework --version 10.0.0-rc.2
                    
NuGet\Install-Package RA.Utilities.Data.EntityFramework -Version 10.0.0-rc.2
                    
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="RA.Utilities.Data.EntityFramework" Version="10.0.0-rc.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RA.Utilities.Data.EntityFramework" Version="10.0.0-rc.2" />
                    
Directory.Packages.props
<PackageReference Include="RA.Utilities.Data.EntityFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RA.Utilities.Data.EntityFramework --version 10.0.0-rc.2
                    
#r "nuget: RA.Utilities.Data.EntityFramework, 10.0.0-rc.2"
                    
#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.
#:package RA.Utilities.Data.EntityFramework@10.0.0-rc.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.0-rc.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.0-rc.2&prerelease
                    
Install as a Cake Tool

RA.Utilities.Data.EntityFramework

NuGet version Codecov GitHub license NuGet Downloads

Provides generic base classes for implementing the Repository and Unit of Work patterns with Entity Framework Core. This package is the concrete implementation layer for the abstractions defined in RA.Utilities.Data.Abstractions.

This library accelerates the setup of a data access layer by providing ready-to-use, generic base classes that handle common data operations. By using these implementations, you can:

  • Rapidly Implement Repositories: Inherit from RepositoryBase, ReadRepositoryBase, or WriteRepositoryBase to get a full suite of data access methods out of the box.
  • Ensure Transactional Integrity: Use the UnitOfWork implementation to manage database transactions and ensure that changes are saved atomically.
  • Promote Best Practices: Encourages a clean, decoupled architecture by building on the abstractions from RA.Utilities.Data.Abstractions.

Getting started

Install the package via the .NET CLI:

dotnet add package RA.Utilities.Data.EntityFramework

Or through the NuGet Package Manager console:

Install-Package RA.Utilities.Data.EntityFramework

🧩 Extensions

This package includes extension methods to simplify service registration for the generic repository patterns.

DependencyInjectionExtensions

Provides extension methods for setting up dependency injection for data-related services.

Namespace: RA.Utilities.Extensions
Source: Extensions/DependencyInjectionExtensions.cs
public static class DependencyInjectionExtensions

Methods

AddRepositoryBase

Adds the generic IRepositoryBase<> and its implementation RepositoryBase<> to the service collection as a scoped service. This allows you to inject IRepositoryBase<T> directly for any entity without creating a specific repository class.

Definition

public static IServiceCollection AddRepositoryBase(this IServiceCollection services)
// In Program.cs
builder.Services.AddRepositoryBase();
// Now you can inject IRepositoryBase in your services
public class MyService(IRepositoryBase productRepository)
{
  // ... use productRepository 
}
AddReadRepositoryBase

Adds the generic IReadRepositoryBase<> and its implementation ReadRepositoryBase<> as a scoped service. Use this if you only need read operations for certain entities, adhering to the Command Query Separation (CQS) principle.

Definition

public static IServiceCollection AddReadRepositoryBase(this IServiceCollection services)
AddWriteRepositoryBase

Adds the generic IWriteRepositoryBase<> and its implementation WriteRepositoryBase<> as a scoped service. Use this if you only need write operations for certain entities.

The WriteRepositoryBase also contains the SaveChangesAsync method. In a Unit of Work pattern, saving changes is typically controlled by the UnitOfWork class, not individual repositories, to ensure transactional integrity.

Definition

public static IServiceCollection AddWriteRepositoryBase(this IServiceCollection services)

🚀 Usage Guide

Here’s a step-by-step guide to setting up a data access layer using this package.

1. Define Your DbContext

Create your Entity Framework DbContext and make sure it implements IDbContext from RA.Utilities.Data.Abstractions.

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    public DbSet<Product> Products { get; set; }
    // Other DbSets...
}

2. Implement Concrete Repositories

Create your own repository interfaces and classes. The interfaces should inherit from IRepository<TEntity> (from RA.Utilities.Data.Abstractions) and the classes should inherit from Repository<TEntity>.

// In your Application/Domain layer (referencing RA.Utilities.Data.Abstractions)
public interface IProductRepository : IRepositoryBase<Product>
{
    Task<IEnumerable<Product>> GetTopSellingProductsAsync(int count);
}

// In your Infrastructure/Data layer (referencing this package)
public class ProductRepository : RepositoryBase<Product>, IProductRepository
{
    public ProductRepository(ApplicationDbContext context) : base(context)
    {
    }

    public async Task<IEnumerable<Product>> GetTopSellingProductsAsync(int count)
    {
        // Custom data access logic
        return await _dbSet.OrderByDescending(p => p.UnitsSold).Take(count).ToListAsync();
    }
}

3. Register Services

In your Program.cs or Startup.cs, register the DbContext, the UnitOfWork, and your custom repositories.

using RA.Utilities.Data.Abstractions;
using RA.Utilities.Data.EntityFramework;

// ...

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

// Register UnitOfWork and Repositories
builder.Services.AddScoped<IUnitOfWork, UnitOfWork<ApplicationDbContext>>();
builder.Services.AddScoped<IProductRepository, ProductRepository>();

4. Use in Your Application

Inject IUnitOfWork into your services or controllers to access repositories and save changes.

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly IUnitOfWork _unitOfWork;

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

    [HttpGet]
    public async Task<IActionResult> GetTopProducts()
    {
        var productRepository = _unitOfWork.GetRepository<IProductRepository>();
        var products = await productRepository.GetTopSellingProductsAsync(5);
        return Ok(products);
    }

    [HttpPost]
    public async Task<IActionResult> CreateProduct(Product product)
    {
        var productRepository = _unitOfWork.GetRepository<IProductRepository>();
        await productRepository.AddAsync(product);
        await _unitOfWork.SaveChangesAsync(); // Commits the transaction
        return CreatedAtAction(nameof(GetProduct), new { id = product.Id }, product);
    }
}

🔗 Dependencies

  • RA.Utilities.Data.Abstractions: Provides the core interfaces (IRepository<T>, IUnitOfWork, etc.) that this package implements.
  • Microsoft.EntityFrameworkCore: The underlying ORM used for the implementations.

Additional documentation

For more information on how this package fits into the larger RA.Utilities ecosystem, please see the main repository documentation.

Feedback

If you have suggestions or find a bug, please open an issue in the RA.Utilities GitHub repository. Contributions are welcome!

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
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
10.0.9-rc 91 11/8/2025
10.0.8-rc 84 11/8/2025
10.0.4-rc 82 11/8/2025
10.0.3-rc 82 11/8/2025
10.0.2-rc.2 89 11/8/2025
10.0.1-rc.2 135 11/5/2025
10.0.0 106 11/24/2025
10.0.0-rc.2 135 10/30/2025