RA.Utilities.Data.EntityFramework
10.0.0-rc.2
Prefix Reserved
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
<PackageReference Include="RA.Utilities.Data.EntityFramework" Version="10.0.0-rc.2" />
<PackageVersion Include="RA.Utilities.Data.EntityFramework" Version="10.0.0-rc.2" />
<PackageReference Include="RA.Utilities.Data.EntityFramework" />
paket add RA.Utilities.Data.EntityFramework --version 10.0.0-rc.2
#r "nuget: RA.Utilities.Data.EntityFramework, 10.0.0-rc.2"
#:package RA.Utilities.Data.EntityFramework@10.0.0-rc.2
#addin nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.0-rc.2&prerelease
#tool nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.0-rc.2&prerelease
RA.Utilities.Data.EntityFramework
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, orWriteRepositoryBaseto get a full suite of data access methods out of the box. - Ensure Transactional Integrity: Use the
UnitOfWorkimplementation 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 | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.0-rc.2.25502.107)
- RA.Utilities.Data.Abstractions (>= 10.0.0-rc.2)
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 |