Albatross.EFCore 10.0.0-rc.127

Prefix Reserved
This is a prerelease version of Albatross.EFCore.
dotnet add package Albatross.EFCore --version 10.0.0-rc.127
                    
NuGet\Install-Package Albatross.EFCore -Version 10.0.0-rc.127
                    
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="Albatross.EFCore" Version="10.0.0-rc.127" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Albatross.EFCore" Version="10.0.0-rc.127" />
                    
Directory.Packages.props
<PackageReference Include="Albatross.EFCore" />
                    
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 Albatross.EFCore --version 10.0.0-rc.127
                    
#r "nuget: Albatross.EFCore, 10.0.0-rc.127"
                    
#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 Albatross.EFCore@10.0.0-rc.127
                    
#: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=Albatross.EFCore&version=10.0.0-rc.127&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Albatross.EFCore&version=10.0.0-rc.127&prerelease
                    
Install as a Cake Tool

Albatross.EFCore

A .NET library that wraps EF Core's DbContext in a clean session abstraction and provides opinionated patterns for entity mapping, repositories, change auditing, and cache eviction. Designed for layered enterprise applications where data access is strictly separated from business logic.

Key Features

  • Session Abstraction - IDbSession / DbSession wraps DbContext as a disposable unit-of-work; repositories depend on it, services never do
  • Entity Mapping Convention - Co-locate entities with their EntityMap<T> class; the Albatross.EFCore.CodeGen source generator auto-registers all maps via modelBuilder.BuildEntityModels()
  • Semantic Exception Conversion - Repository<T>.SaveChangesAsync converts database constraint violations into semantic exceptions (ConflictException, NotFoundException, PreconditionFailedException) via ISemanticExceptionConverter
  • Change Report Interceptor - ChangeReportInterceptor<TEntity> captures per-property before/after snapshots and invokes a callback after each successful save
  • Audit Trail Interceptor - ChangeAuditInterceptor<TChangeEntity, TEntityId, TActorId> writes typed audit records for every IAuditable<T> entity that is modified or deleted
  • Cache Eviction Interceptor - CacheEvictionInterceptor triggers cache invalidation for modified or deleted entities post-save
  • JSON Column Helpers - HasImmutableJsonProperty<T> and HasJsonCollectionProperty<T> map complex types to varchar(max) JSON columns with correct change-tracking semantics
  • UTC DateTime Fix - UtcDateTimeProperty() ensures DateTime columns round-trip with DateTimeKind.Utc

Quick Start

Define a session, an entity with its map, and a repository:

// 1. Session — one per bounded context
using Crm.AutoGenerated; // where the source generator puts BuildEntityModels()

public interface ICrmDbSession : IDbSession { }

public class CrmDbSession : DbSession, ICrmDbSession {
    public CrmDbSession(DbContextOptions options) : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder) {
        modelBuilder.HasDefaultSchema("crm");
        modelBuilder.BuildEntityModels(); // auto-registers all EntityMap<T> in this assembly
    }
}

// 2. Entity + map in the same file
public class Company {
    public required Guid Id { get; init; }
    [MaxLength(256)] public required string Name { get; set; }
}

public class CompanyEntityMap : EntityMap<Company> {
    public override void Map(EntityTypeBuilder<Company> builder) {
        builder.HasKey(x => x.Id);
        builder.Property(x => x.Id).ValueGeneratedNever();
        builder.HasIndex(x => x.Name).IsUnique();
    }
}

// 3. Repository — one per aggregate root
public class CompanyRepository : Repository<ICrmDbSession> {
    public CompanyRepository(ICrmDbSession session, ISemanticExceptionConverter converter) : base(session, converter) { }

    public async Task<Company> GetById(Guid id, CancellationToken ct) {
        var entity = await session.DbContext.Set<Company>()
            .FirstOrDefaultAsync(x => x.Id == id, ct);
        if (entity == null) throw new NotFoundException<Company>(id);
        return entity;
    }
}

// 4. Save at the application boundary (controller / command handler)
await repository.SaveChangesAsync(cancellationToken);
// Constraint violations throw semantic exceptions (ConflictException, NotFoundException, PreconditionFailedException)

Dependencies

  • Microsoft.EntityFrameworkCore 10.0.5+
  • Microsoft.EntityFrameworkCore.Relational 10.0.5+
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5+

Prerequisites

  • .NET 10.0+
  • C# Compiler 4.12.0+ — required by the Albatross.EFCore.CodeGen source generator. Satisfied by .NET 9 SDK or Visual Studio 2022 with .NET 8. When using .NET 8 SDK with VS Code, Rider, or a terminal, add Microsoft.Net.Compilers.Toolset 4.12.0+ to your project.

Documentation

Complete Documentation

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

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Albatross.EFCore:

Package Downloads
Albatross.EFCore.SqlServer

SqlServer Setup for Albatross.EFCore

Albatross.EFCore.PostgreSQL

PostgresSQL Setup for Albatross.EFCore

Albatross.EFCore.ChangeReporting

Package Description

Albatross.EFCore.AutoCacheEviction

Package Description

Albatross.EFCore.Admin

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-rc.127 75 7/28/2026
10.0.0-rc.124 70 7/24/2026
10.0.0-rc.121 69 7/17/2026
10.0.0-rc.117 82 7/11/2026
10.0.0-rc.113 86 7/8/2026
10.0.0-rc.112 90 7/8/2026
Loading failed