Covali.EntityFramework 9.0.2

dotnet add package Covali.EntityFramework --version 9.0.2
                    
NuGet\Install-Package Covali.EntityFramework -Version 9.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Covali.EntityFramework" Version="9.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Covali.EntityFramework" Version="9.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Covali.EntityFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Covali.EntityFramework --version 9.0.2
                    
#r "nuget: Covali.EntityFramework, 9.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Covali.EntityFramework@9.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Covali.EntityFramework&version=9.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Covali.EntityFramework&version=9.0.2
                    
Install as a Cake Tool

Covali.EntityFramework

NuGet License: MIT

Simplifies Entity Framework Core implementation by providing automatic timestamp management and useful value converters.

Features

  • Automatic Timestamp Tracking: Automatically sets CreatedAt, UpdatedAt, and DeletedAt timestamps on entities
  • Soft Delete Support: Implements soft delete pattern by setting DeletedAt instead 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 CreatedAt to DateTimeOffset.UtcNow
  • Modified entities: Sets UpdatedAt to DateTimeOffset.UtcNow
  • Deleted entities: Sets DeletedAt to DateTimeOffset.UtcNow and 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

https://github.com/cva-pasha/Covali.EntityFramework

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
9.0.2 284 11/9/2025
9.0.1 232 11/9/2025
9.0.0 237 11/9/2025