GM.EntityFramework 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GM.EntityFramework --version 1.2.0
                    
NuGet\Install-Package GM.EntityFramework -Version 1.2.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="GM.EntityFramework" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GM.EntityFramework" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="GM.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 GM.EntityFramework --version 1.2.0
                    
#r "nuget: GM.EntityFramework, 1.2.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 GM.EntityFramework@1.2.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=GM.EntityFramework&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=GM.EntityFramework&version=1.2.0
                    
Install as a Cake Tool

GM.EntityFramework

CI NuGet License: MIT

A lightweight DDD + Entity Framework Core toolkit for .NET: base entities, value objects, the specification pattern, a generic repository, and a unit of work with transactions and automatic auditing. Targets .NET 10.

Packages

The three packages version and release together (lockstep):

Package What it gives you
GM.EntityFramework.Domain Entities, value objects, specifications, results, domain-event and repository abstractions (no EF dependency to reference in your domain layer beyond EF Core primitives).
GM.EntityFramework.Persistence The EF Core implementation: GenericRepository, GenericUnitOfWork, and an auditing GenericDbContext.
GM.EntityFramework Meta-package that pulls in both of the above.
dotnet add package GM.EntityFramework

Quick start

1. Define entities

using GM.EntityFramework.Domain.Base;

public class Product : AuditableEntity<Guid>   // adds CreatedAt / UpdatedAt (set automatically)
{
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
}

Base classes: Entity<TKey>AuditableEntity<TKey> (timestamps) → SoftDeletableEntity<TKey> (adds IsActive / IsDeleted / IsHidden with SoftRemove(), RestoreAll(), etc.). There's also ValueObject for equality-by-value types.

2. Create a DbContext

Inherit GenericDbContext — it stamps CreatedAt/UpdatedAt on save automatically.

using GM.EntityFramework.Persistence;
using Microsoft.EntityFrameworkCore;

public class AppDbContext(DbContextOptions options) : GenericDbContext(options)
{
    public DbSet<Product> Products => Set<Product>();
}

3. Register and use the repository + unit of work

services.AddDbContext<AppDbContext>(o => o.UseSqlServer(connectionString));
services.AddScoped<IGenericUnitOfWork, GenericUnitOfWork<AppDbContext>>();
services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<,>));
await repository.AddAsync(new Product { Name = "Book", Price = 9.99m });
await unitOfWork.SaveChangesAsync();

var cheap = await repository.FindAsync(p => p.Price < 10);
var exists = await repository.ExistsAsync(p => p.Name == "Book");

4. Specifications

Encapsulate query logic and compose it with And / Or / Not:

using GM.EntityFramework.Domain.Specifications;

public class CheapProductsSpec : BaseSpecification<Product>
{
    public CheapProductsSpec()
    {
        AddCriteria(p => p.Price < 10);
        ApplyOrdering(nameof(Product.Name));
        ApplyPaging(currentPage: 1, pageSize: 20);
    }
}

var page = await repository.ListAsync(new CheapProductsSpec());

5. Transactions

await unitOfWork.ExecuteInTransactionAsync(async () =>
{
    await repository.AddAsync(product);
    // ... more work; commits on success, rolls back on exception
});

Concurrency conflicts surface as a ConcurrencyException.

Sample application

A complete, runnable DDD + CQRS example built on these packages lives in a separate repo: GM.EntityFramework.Samples. It's a layered ASP.NET Core Web API (Domain / Application / Persistence / API) that shows how the pieces fit together in a real project:

  • A Sample aggregate root (SoftDeletableEntity<int>, IAggregateRoot) with child SampleItem entities, factory methods, and encapsulated mutations.
  • A custom ISampleRepository : IGenericRepository<Sample>, implemented by deriving from GenericRepository<Sample, ApplicationDbContext>.
  • An ApplicationDbContext : GenericDbContext that applies EF configurations from the assembly and gets automatic CreatedAt / UpdatedAt auditing for free.
  • A UnitOfWork : GenericUnitOfWork<ApplicationDbContext> that exposes the aggregate repository.
  • CQRS commands (create / update / delete) and queries (details / list), EF Core migrations, and a PostgreSQL (Npgsql) provider.

Clone it to see the library used end-to-end.

Repository layout

GM.EntityFramework/
├── GM.EntityFramework.Domain/        # abstractions (entities, specifications, results, events)
├── GM.EntityFramework.Persistence/   # EF Core implementation (repository, UoW, DbContext)
├── GM.EntityFramework/               # meta-package
└── tests/GM.EntityFramework.Tests/   # xUnit tests (SQLite in-memory for persistence)

Building & testing

dotnet build -c Release
dotnet test  -c Release

Releasing

Versioning is automated from Conventional Commits — see CONTRIBUTING.md. All three packages share one version (Directory.Build.props) and publish together to nuget.org on each release.

License

MIT — see LICENSE.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 92 7/30/2026
1.2.0 97 7/28/2026
1.1.0 110 7/2/2026
1.0.1 294 6/13/2025
1.0.0 224 5/4/2025