Covali.EntityFramework
9.0.2
dotnet add package Covali.EntityFramework --version 9.0.2
NuGet\Install-Package Covali.EntityFramework -Version 9.0.2
<PackageReference Include="Covali.EntityFramework" Version="9.0.2" />
<PackageVersion Include="Covali.EntityFramework" Version="9.0.2" />
<PackageReference Include="Covali.EntityFramework" />
paket add Covali.EntityFramework --version 9.0.2
#r "nuget: Covali.EntityFramework, 9.0.2"
#:package Covali.EntityFramework@9.0.2
#addin nuget:?package=Covali.EntityFramework&version=9.0.2
#tool nuget:?package=Covali.EntityFramework&version=9.0.2
Covali.EntityFramework
Simplifies Entity Framework Core implementation by providing automatic timestamp management and useful value converters.
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 - Compressed Text Storage: GZip-compress large text fields to save database storage space
- Zero Configuration: Works automatically once the interceptor is registered
- Type-Safe: Uses strongly-typed interfaces and converters
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.
Value Converters
CompressedTextConverter
Compresses large text fields using GZip compression to save database storage space. Ideal for HTML content, JSON data, large templates, or any text that benefits from compression.
Usage Example:
public sealed class EmailTemplate
{
public Guid Id { get; init; }
public required string Name { get; set; }
// Large HTML content stored compressed in database
public required string HtmlContent { get; set; }
}
public class EmailTemplateConfiguration : IEntityTypeConfiguration<EmailTemplate>
{
public void Configure(EntityTypeBuilder<EmailTemplate> builder)
{
builder.Property(e => e.HtmlContent)
.HasConversion(new CompressedTextConverter())
.HasColumnType("varbinary(max)");
}
}
The converter automatically:
- Compresses text to bytes when saving to database
- Decompresses bytes to text when reading from database
- Handles null/empty values gracefully
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.