Benday.EfCore 11.0.6-alpha

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

Benday.EfCore

Base classes for the repository pattern, adapter pattern, and service layer pattern with Entity Framework Core. Hide your dependencies, keep your domain models clean, and make your business logic testable without a database.

Packages

Package Description
Benday.EfCore Provider-agnostic core: entities, domain models, adapters, repositories, service layers, DI registration
Benday.EfCore.SqlServer SQL Server wiring: UseConnectionString, ApplyBendaySqlServerConcurrency, design-time factory
Benday.EfCore.Testing Test doubles: InMemoryRepository<T>, FakeValidatorStrategy<T>, FakeUsernameProvider

About

Written by Benjamin Day Pluralsight Author | Microsoft MVP | Scrum.org Professional Scrum Trainer https://www.benday.com info@benday.com

Got ideas for features you'd like to see? Found a bug? Let us know by submitting an issue. Want to contribute? Submit a pull request.

Source code

API Documentation

What's in v11

v11 is a ground-up modernization:

  • .NET 10 and EF Core 10.
  • Async throughout — every repository and service method is async.
  • Shared interface layer via Benday.Common.Interfaces (IEntityIdentity<int>, IDeleteable, IAsyncReadableRepository<T,int>, IAsyncService<T,int>). This is the same contract used by Benday.CosmosDb — swap the storage, keep the contract.
  • Adapter + service layer base classes for mapping between domain models and EF entities.
  • No search predicate machinery — write your own LINQ queries in your repository.

Upgrading from v10? This is a breaking release. The search base class (SqlEntityFrameworkSearchableRepositoryBase) and its predicate methods, the LinqPredicateExtensions/ParameterSubstitutionVisitor helpers, and the dependency on Benday.Common (IInt32Identity) have all been removed. Types now live in feature namespaces (Benday.EfCore.SqlServer.Entities, .Repositories, .Adapters, .ServiceLayers, .DomainModels, .Registration).

The layers

Layer Base class Purpose
Entity EntityBase, CoreFieldsEntityBase EF Core entities. CoreFieldsEntityBase adds audit fields + a concurrency token (mapped per provider).
Domain model DomainModelBase, CoreFieldsDomainModelBase Business-logic types on the far side of the adapter boundary. EF never sees them.
Adapter AdapterBase<TModel, TEntity> Bidirectional mapping, including collection merge (match by Id, add new, mark missing for delete).
Repository EfCoreRepositoryBase, EfCoreCrudRepositoryBase Async CRUD + the dependent-entity (aggregate) save/delete lifecycle. Implements IAsyncReadableRepository<T,int>.
Service ServiceLayerBase, CoreFieldsServiceLayerBase Orchestration: validate → get/create → adapt → save → copy back. CoreFields variant populates audit fields.
Registration EfCoreRegistrationHelper<TDbContext> Fluent DI: services.AddBendayEfCore<MyDbContext>(...).

The companion package Benday.EfCore.Testing provides InMemoryRepository<T>, FakeValidatorStrategy<T>, and FakeUsernameProvider so you can unit-test your service layer with no database.

Aggregate roots and dependent entities

An entity that owns children overrides GetDependentEntities() to expose each child collection as a DependentEntityCollection<T>. The repository then handles the child lifecycle on save: children flagged IsMarkedForDelete are removed from the database, and the in-memory collection is pruned afterward.

Optimistic concurrency note

CoreFieldsEntityBase exposes a Timestamp property for optimistic concurrency. The property is provider-agnostic — SQL Server consumers map it as rowversion by calling modelBuilder.ApplyBendaySqlServerConcurrency() in OnModelCreating. Because of this token, you cannot blind-update a detached CoreFields entity — EF has no original rowversion to check and the update affects zero rows. Always load the entity first (so it carries its token), then modify and save. The service layer does exactly this (GetByIdAsync → adapt → save). Plain EntityBase entities (no token) can be attach-updated while detached.

Build and test

# Build
dotnet build Benday.EfCore.slnx

# Unit tests (in-memory, no database required)
dotnet test Benday.EfCore.SqlServer.UnitTests

# Integration tests (require SQL Server — see below)
dotnet test Benday.EfCore.SqlServer.IntegrationTests

Local SQL Server for integration tests

The integration tests need SQL Server at localhost (sa / Pa$$word). Start it in Docker:

./start-local-dev.ps1          # starts the sql_server container
./start-local-dev.ps1 -Pull    # also pull the latest image
./start-local-dev.ps1 -Remove  # recreate the container from scratch

The benday-efcore-sqlserver database and its schema are created automatically via EF Core migrations on first test run. When SQL Server is not reachable, the integration tests skip (rather than fail), so dotnet test on the whole solution stays green without a database.

CI/CD

GitHub Actions runs on every push and pull request to main:

  1. Unit tests — builds all packages, runs unit tests, packs NuGet artifacts
  2. Integration tests — runs against SQL Server 2025 in a container
  3. Deploy — pushes to NuGet.org on push to main (requires NUGET_API_KEY secret)

Pull requests get full validation without publishing.

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 (2)

Showing the top 2 NuGet packages that depend on Benday.EfCore:

Package Downloads
Benday.EfCore.SqlServer

SQL Server wiring for Benday.EfCore: connection-string registration (UseConnectionString), rowversion optimistic concurrency (ApplyBendaySqlServerConcurrency), and a design-time DbContext factory base. Pairs with the provider-agnostic Benday.EfCore package. Hide your dependencies.

Benday.EfCore.Testing

Test doubles and helpers for testing applications built with Benday.EfCore. Includes InMemoryRepository, FakeValidatorStrategy, and FakeUsernameProvider.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.6-alpha 69 6/22/2026