DotEmilu.EntityFrameworkCore
2.0.0
dotnet add package DotEmilu.EntityFrameworkCore --version 2.0.0
NuGet\Install-Package DotEmilu.EntityFrameworkCore -Version 2.0.0
<PackageReference Include="DotEmilu.EntityFrameworkCore" Version="2.0.0" />
<PackageVersion Include="DotEmilu.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="DotEmilu.EntityFrameworkCore" />
paket add DotEmilu.EntityFrameworkCore --version 2.0.0
#r "nuget: DotEmilu.EntityFrameworkCore, 2.0.0"
#addin nuget:?package=DotEmilu.EntityFrameworkCore&version=2.0.0
#tool nuget:?package=DotEmilu.EntityFrameworkCore&version=2.0.0
DotEmilu EF Core
A simple, easy-to-use .NET library designed for EF Core interceptors and auditable entities.
Features
- Supports CREATE, UPDATE, DELETE tracking.
- Provides properties for base and auditable entities.
- Contracts (interfaces) and abstractions for easy inheritance and implementation.
- Supports generic keys for entity IDs and user keys for audit purposes.
Context User
supports generic ID types for better flexibility.
Enhanced Interceptors
- SoftDeleteInterceptor: Handles soft deletes for entities implementing
IBaseEntity
. - AuditableEntityInterceptor: Tracks changes for entities implementing
IBaseAuditableEntity
, now with support for generic user keys.
Configuration and Extensibility
- Base configurations using IEntityTypeConfiguration for a consistent mapping strategy.
- Extension methods to register multiple configurations:
- By passing an assembly or individually by type.
- Flexible Dependency Injection (DI) setup:
- Register interceptors individually or by assembly for multiple interceptors.
Why Use DotEmilu EF Core?
Ideal for projects requiring:
- Consistent tracking and flexible auditing mechanisms.
- Easy integration of EF Core interceptors.
- A scalable, customizable approach to entity configurations and dependency injection.
How to Use
Follow these simple steps to get started:
Define Your Database Entities
Create your database entities as needed for your application.View all contracts for
BaseEntity
View all contracts for
BaseAuditableEntity
public class Person : BaseEntity<Guid> { public string Name { get; set; } = null!; public string? LastName { get; set; } } public class Song : BaseAuditableEntity<int, Guid> { public required string Name { get; set; } }
Implement Context User Information
Create an implementation to retrieve user context information (e.g., user ID, roles).//Feel free to inject your necessary dependencies to provide user information. public class ContextUser : IContextUser<Guid> { public Guid Id => Guid.Parse("66931274-341d-41a0-0ec4-08dd5e9e0461"); }
Working with Unit of Work
Inherit your entity interfaces and use EF Core features in a decoupled manner.public interface ICommands : IUnitOfWork { DbSet<Person> Persons { get; } } public class PersonHandler(ICommands commands) { public async Task WorkAsync() { var person = await commands.Persons.FirstOrDefaultAsync(); person!.Name = "NEW NAME!"; await commands.SaveChangesAsync(); } }
Registering Base Configurations
Different methods to register base configurations.public class SqlServerContext(DbContextOptions<SqlServerContext> options) : DbContext(options) { protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder //.ApplyBaseAuditableEntityConfiguration<int>(strategy: MappingStrategy.Tpt) //method 1 .ApplyBaseAuditableEntityConfiguration(Assembly.GetExecutingAssembly()) //method 2 //.ApplyBaseEntityConfiguration<Guid>(strategy: MappingStrategy.Tph, enableRowVersion: true) //method 1 .ApplyBaseEntityConfiguration(Assembly.GetExecutingAssembly()) //method 2 .ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } public DbSet<Person> Persons => Set<Person>(); public DbSet<Song> Songs => Set<Song>(); }
Register the Interceptor
Add your custom interceptor to the dependency injection container in your application.builder.Services .AddSoftDeleteInterceptor() //.AddAuditableEntityInterceptor<ContextUser, Guid>() //method 1 .AddAuditableEntityInterceptors(Assembly.GetExecutingAssembly()) //method 2
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.14)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added generic support for entities, soft delete handling, and improved DI and configuration.