RA.Utilities.Data.EntityFramework
10.0.1
Prefix Reserved
See the version list below for details.
dotnet add package RA.Utilities.Data.EntityFramework --version 10.0.1
NuGet\Install-Package RA.Utilities.Data.EntityFramework -Version 10.0.1
<PackageReference Include="RA.Utilities.Data.EntityFramework" Version="10.0.1" />
<PackageVersion Include="RA.Utilities.Data.EntityFramework" Version="10.0.1" />
<PackageReference Include="RA.Utilities.Data.EntityFramework" />
paket add RA.Utilities.Data.EntityFramework --version 10.0.1
#r "nuget: RA.Utilities.Data.EntityFramework, 10.0.1"
#:package RA.Utilities.Data.EntityFramework@10.0.1
#addin nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.1
#tool nuget:?package=RA.Utilities.Data.EntityFramework&version=10.0.1
RA.Utilities.Data.EntityFramework
This package provides concrete implementations of the repository and unit of work patterns for Entity Framework Core, based on the abstractions from RA.Utilities.Data.Abstractions. It's designed to accelerate the setup of a data access layer in a clean, testable, and maintainable way.
✨ Key Features
- Generic Repository Implementations: Provides ready-to-use base classes for repository patterns, saving you from writing boilerplate CRUD (Create, Read, Update, Delete) code.
- Command Query Separation (CQS): Offers distinct
ReadRepositoryBase<T>andWriteRepositoryBase<T>classes to help you build a clean architecture where read and write operations are separated. - Performance-Optimized Queries: The
ReadRepositoryBase<T>usesAsNoTracking()by default for more efficient data retrieval. - Automatic Timestamping: Includes a
BaseEntitySaveChangesInterceptorthat automatically setsCreatedAtandLastModifiedAtproperties on your entities when they are saved. - Simplified Dependency Injection: Provides extension methods to register your repositories with a single line of code in
Program.cs.
Installation
You can install the package via the .NET CLI:
dotnet add package RA.Utilities.Data.EntityFramework
Install-Package RA.Utilities.Data.EntityFramework
Core Components
Repository Implementations
This package provides concrete implementations for the interfaces defined in RA.Utilities.Data.Abstractions.
RepositoryBase<T>: A full-featured generic repository that implementsIRepositoryBase<T>for complete CRUD functionality. It's a convenient all-in-one solution for services that need to both query and modify data.ReadRepositoryBase<T>: A read-only repository implementingIReadRepositoryBase<T>. It is optimized for performance by usingAsNoTracking()on queries, making it ideal for the "Query" side of a CQRS architecture.WriteRepositoryBase<T>: A write-only repository implementingIWriteRepositoryBase<T>. It is designed for "Command" operations like adding, updating, and deleting entities.
Interceptors
BaseEntitySaveChangesInterceptor: An Entity Framework Core interceptor that automatically populates timestamp properties (CreatedAt,LastModifiedAt) on entities inheriting fromBaseEntitybefore changes are saved to the database. This ensures consistent and accurate auditing without manual intervention.
Dependency Injection Extensions
The DependencyInjectionExtensions class simplifies the registration of the generic repositories in your application's DI container.
AddRepositoryBase(): Registers the fullIRepositoryBase<>implementation.AddReadRepositoryBase(): Registers the read-onlyIReadRepositoryBase<>implementation.AddWriteRepositoryBase(): Registers the write-onlyIWriteRepositoryBase<>implementation.
Usage Example
Here is how you can configure and use the components from this package in an ASP.NET Core application.
1. Define Your DbContext
First, ensure your DbContext implements the IDbContext interface from RA.Utilities.Data.Abstractions.
public class ApplicationDbContext : DbContext, IDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Product> Products { get; set; }
}
2. Register Services in Program.cs
In your Program.cs, register your DbContext, the interceptor, and the desired repository implementations.
using RA.Utilities.Data.EntityFramework.Extensions;
using RA.Utilities.Data.EntityFramework.Interceptors;
var builder = WebApplication.CreateBuilder(args);
// 1. Register the SaveChangesInterceptor
builder.Services.AddScoped<BaseEntitySaveChangesInterceptor>();
// 2. Register the DbContext and add the interceptor
builder.Services.AddDbContext<ApplicationDbContext>((provider, options) =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))
.AddInterceptors(provider.GetRequiredService<BaseEntitySaveChangesInterceptor>()));
// 3. Register the generic repositories
builder.Services.AddRepositoryBase(); // For IRepositoryBase<>
builder.Services.AddReadRepositoryBase(); // For IReadRepositoryBase<>
builder.Services.AddWriteRepositoryBase(); // For IWriteRepositoryBase<>
// Register your custom repositories
builder.Services.AddScoped<IProductRepository, ProductRepository>();
var app = builder.Build();
3. Implement a Custom Repository (Optional)
You can extend the generic repositories to add custom data access methods.
public interface IProductRepository : IRepositoryBase<Product>
{
Task<Product?> GetProductByNameAsync(string name);
}
public class ProductRepository : RepositoryBase<Product>, IProductRepository
{
public ProductRepository(ApplicationDbContext dbContext) : base(dbContext)
{
}
public async Task<Product?> GetProductByNameAsync(string name)
{
return await _dbSet.FirstOrDefaultAsync(p => p.Name == name);
}
}
4. Use in a Service
Finally, inject the repository interfaces into your services to interact with the database.
public class ProductService
{
private readonly IProductRepository _productRepository;
public ProductService(IProductRepository productRepository)
{
_productRepository = productRepository;
}
public async Task<Product?> GetProductDetailsAsync(Guid id)
{
// Use a method from the base repository
return await _productRepository.GetByIdAsync(id);
}
public async Task CreateProductAsync(string name, decimal price)
{
var newProduct = new Product { Name = name, Price = price };
// The BaseEntitySaveChangesInterceptor will automatically set CreatedAt
await _productRepository.AddAsync(newProduct);
}
}
| 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)
- RA.Utilities.Data.Abstractions (>= 10.0.1)
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 | 113 | 11/8/2025 |
| 10.0.8-rc | 99 | 11/8/2025 |
| 10.0.4-rc | 96 | 11/8/2025 |
| 10.0.3-rc | 98 | 11/8/2025 |
| 10.0.2-rc.2 | 106 | 11/8/2025 |
| 10.0.1 | 215 | 12/14/2025 |
| 10.0.1-rc.2 | 151 | 11/5/2025 |
| 10.0.0 | 188 | 11/24/2025 |
| 10.0.0-rc.2 | 150 | 10/30/2025 |