Covali.EntityFramework
9.0.0
See the version list below for details.
dotnet add package Covali.EntityFramework --version 9.0.0
NuGet\Install-Package Covali.EntityFramework -Version 9.0.0
<PackageReference Include="Covali.EntityFramework" Version="9.0.0" />
<PackageVersion Include="Covali.EntityFramework" Version="9.0.0" />
<PackageReference Include="Covali.EntityFramework" />
paket add Covali.EntityFramework --version 9.0.0
#r "nuget: Covali.EntityFramework, 9.0.0"
#:package Covali.EntityFramework@9.0.0
#addin nuget:?package=Covali.EntityFramework&version=9.0.0
#tool nuget:?package=Covali.EntityFramework&version=9.0.0
Covali.EntityFramework
Simplifies Entity Framework Core implementation by providing automatic timestamp management for entities.
Features
- Automatic Timestamp Tracking: Automatically sets
CreatedAt,UpdatedAt, andDeletedAttimestamps on entities - Soft Delete Support: Implements soft delete pattern by setting
DeletedAtinstead of physically removing records - Zero Configuration: Works automatically once the interceptor is registered
- Type-Safe: Uses strongly-typed interface
IHasTimestamps
Installation
dotnet add package Covali.EntityFramework
Quick Start
1. Implement the Interface
Add the IHasTimestamps interface to your entities:
using Covali.EntityFramework;
public sealed class Product : IHasTimestamps
{
public Guid Id { get; init; }
public required string Name { get; set; }
// IHasTimestamps properties
public DateTimeOffset CreatedAt { get; private set; }
public DateTimeOffset? UpdatedAt { get; private set; }
public DateTimeOffset? DeletedAt { get; private set; }
}
2. Register the Interceptor
Add the TimestampsInterceptor to your DbContext:
using Covali.EntityFramework.Interceptors;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.AddInterceptors(new TimestampsInterceptor());
}
}
Or with dependency injection:
services.AddDbContext<ApplicationDbContext>((provider, options) =>
{
options.UseSqlServer(connectionString)
.AddInterceptors(new TimestampsInterceptor());
});
3. Use Your Entities
The timestamps are managed automatically:
// Create - CreatedAt is set automatically
var product = new Product { Name = "Widget" };
context.Products.Add(product);
await context.SaveChangesAsync();
// product.CreatedAt is now set to current UTC time
// Update - UpdatedAt is set automatically
product.Name = "Updated Widget";
await context.SaveChangesAsync();
// product.UpdatedAt is now set to current UTC time
// Delete - DeletedAt is set automatically (soft delete)
context.Products.Remove(product);
await context.SaveChangesAsync();
// product.DeletedAt is now set to current UTC time
// Entity state changed from Deleted to Modified
How It Works
The TimestampsInterceptor hooks into Entity Framework Core's change tracking:
- Added entities: Sets
CreatedAttoDateTimeOffset.UtcNow - Modified entities: Sets
UpdatedAttoDateTimeOffset.UtcNow - Deleted entities: Sets
DeletedAttoDateTimeOffset.UtcNowand changes state to Modified (soft delete)
All timestamps use UTC to avoid timezone ambiguities.
Requirements
- .NET 9.0 or higher
- Entity Framework Core 9.0 or higher
License
MIT License - see LICENSE
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. net10.0 was computed. 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Covali.EntityFramework:
| Package | Downloads |
|---|---|
|
Covali.Templates.EntityFramework
Entity Framework Core infrastructure for Covali.Templates. Provides Template entity, AbstractTemplateDbContext, ITemplateDbContext interface, and EF Core configurations with optimized indexes for multi-tenant template storage. |
GitHub repositories
This package is not used by any popular GitHub repositories.