HoneyDrunk.Data.EntityFramework 0.8.0

dotnet add package HoneyDrunk.Data.EntityFramework --version 0.8.0
                    
NuGet\Install-Package HoneyDrunk.Data.EntityFramework -Version 0.8.0
                    
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="HoneyDrunk.Data.EntityFramework" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HoneyDrunk.Data.EntityFramework" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="HoneyDrunk.Data.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 HoneyDrunk.Data.EntityFramework --version 0.8.0
                    
#r "nuget: HoneyDrunk.Data.EntityFramework, 0.8.0"
                    
#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 HoneyDrunk.Data.EntityFramework@0.8.0
                    
#: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=HoneyDrunk.Data.EntityFramework&version=0.8.0
                    
Install as a Cake Addin
#tool nuget:?package=HoneyDrunk.Data.EntityFramework&version=0.8.0
                    
Install as a Cake Tool

HoneyDrunk.Data.EntityFramework

Entity Framework Core provider implementation for HoneyDrunk.Data. This package is provider-agnostic—database-specific configuration belongs in specialization packages (e.g., HoneyDrunk.Data.SqlServer).

Purpose

Implements the persistence abstractions using Entity Framework Core. Provides:

  • Base DbContext with tenant identity and correlation context access (not automatic filtering)
  • Repository implementation wrapping DbSet
  • EF-backed unit-of-work abstraction
  • Command interceptor for correlation tagging (relational providers, opt-in)
  • Health contributor for database connectivity

Allowed Dependencies

  • HoneyDrunk.Data.Abstractions - The contracts this package implements
  • HoneyDrunk.Data - The orchestration layer (required)
  • Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • HoneyDrunk.Standards - Analyzer package only (PrivateAssets=all)

Note: Relational providers are required for diagnostics features (command interception). Non-relational EF Core providers may not support all features.

What Must Never Be Added

  • No database-specific packages - SQL Server, PostgreSQL, etc. belong in their respective projects
  • No transport or auth references - HoneyDrunk.Transport and HoneyDrunk.Auth are not data concerns

Namespace Layout

HoneyDrunk.Data.EntityFramework
├── Context/              # Base DbContext
│   └── HoneyDrunkDbContext.cs
├── Diagnostics/          # Interceptors and health
│   ├── CorrelationCommandInterceptor.cs
│   └── DbContextHealthContributor.cs
├── Modeling/             # Optional model conventions
│   └── ModelBuilderConventions.cs
├── Registration/         # DI extensions
│   ├── EfDataOptions.cs
│   └── ServiceCollectionExtensions.cs
├── Repositories/         # Repository implementation
│   └── EfRepository.cs
└── Transactions/         # UoW and transaction scope
    ├── EfTransactionScope.cs
    ├── EfUnitOfWork.cs
    └── EfUnitOfWorkFactory.cs

Usage

// Orchestration layer is required
services.AddHoneyDrunkData();

// Register EF Core provider (database configuration deferred to specialization package)
services.AddHoneyDrunkDataEntityFramework<MyDbContext>(
    options =>
    {
        // Database provider configured here or via specialization package
        // Example: options.UseSqlServer(...) requires HoneyDrunk.Data.SqlServer
    },
    efOptions =>
    {
        efOptions.EnableCorrelationInterceptor = true;  // Requires relational provider
        efOptions.RegisterHealthContributors = true;
    });

// Or use a specialization package (recommended):
// services.AddHoneyDrunkDataSqlServer<MyDbContext>(...);

Creating a DbContext

public class MyDbContext : HoneyDrunkDbContext
{
    public MyDbContext(
        DbContextOptions<MyDbContext> options,
        ITenantAccessor tenantAccessor,
        IDataDiagnosticsContext diagnosticsContext)
        : base(options, tenantAccessor, diagnosticsContext)
    {
    }

    public DbSet<MyEntity> MyEntities => Set<MyEntity>();

    protected override void ApplyConfigurations(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(MyDbContext).Assembly);
        
        // Tenant filtering must be configured explicitly per entity
        // Example: modelBuilder.Entity<MyEntity>().HasQueryFilter(e => e.TenantId == CurrentTenantId.Value);
    }
}

Note: HoneyDrunkDbContext exposes CurrentTenantId and CorrelationId but does not automatically apply tenant filtering. Applications must configure query filters explicitly.

Using Repositories

public class MyService
{
    private readonly IUnitOfWork<MyDbContext> _unitOfWork;

    public MyService(IUnitOfWork<MyDbContext> unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task CreateAsync(MyEntity entity, CancellationToken ct)
    {
        var repo = _unitOfWork.Repository<MyEntity>();
        await repo.AddAsync(entity, ct);
        await _unitOfWork.SaveChangesAsync(ct);  // Context-local save
    }
}

Note: EfRepository<T> implements IRepository<T> (which extends IReadOnlyRepository<T>). No separate read-only implementation exists—read-only access is a usage pattern, not a distinct type.

Lifetime and Threading

  • Scoped lifetime expected. This implementation assumes scoped DbContext lifetime (per-request in web applications).
  • Not thread-safe. DbContext and EfUnitOfWork are not thread-safe; do not share across threads.
  • Factory for controlled lifetime. Use EfUnitOfWorkFactory with IDbContextFactory<T> for background jobs or batch processing.

Correlation Tracking

Correlation tagging is opt-in and conditional:

  • Requires EnableCorrelationInterceptor = true
  • Requires relational EF Core provider
  • Requires diagnostics context to have a correlation ID

When all conditions are met, SQL commands include correlation comments:

/* correlation:01JXYZ... */
SELECT * FROM MyEntities WHERE Id = @p0
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on HoneyDrunk.Data.EntityFramework:

Package Downloads
HoneyDrunk.Data.SqlServer

SQL Server specialization for HoneyDrunk.Data. Complete architecture overhaul with SQL Server and Azure SQL configuration, model conventions, retry-on-failure support, and enhanced health diagnostics.

HoneyDrunk.Operator.Data

Durable storage for HoneyDrunk.Operator over HoneyDrunk.Data's Entity Framework layer: approvals and decisions, manual pauses, and budget spend survive restarts.

HoneyDrunk.Memory.Providers.Data

Durable HoneyDrunk agent-memory store over HoneyDrunk.Data's Entity Framework layer: memory survives a restart and is shared by every host on one database.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.0 382 11/11/2026
0.7.2 577 11/5/2026
0.7.1 1,272 9/26/2026
0.7.0 686 5/27/2026
0.6.0 170 5/18/2026
0.5.1 160 5/4/2026
0.5.0 143 5/4/2026
0.4.0 150 4/25/2026
0.3.0 159 2/15/2026
0.2.0 174 1/6/2026

v0.8.0: Target .NET 11 runtimes and add optional source-bounded ordered repository reads. Abstractions retain .NET 10 support.