GM.EntityFramework.Domain 1.2.1

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

<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.EntityFramework/master/icon.png" alt="GM.EntityFramework" width="140" height="140" /> </p>

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

Showing the top 5 NuGet packages that depend on GM.EntityFramework.Domain:

Package Downloads
GM.EntityFramework.Persistence

EF Core persistence for GM.EntityFramework.Domain — a generic repository, unit of work with transactions, and an auditing DbContext.

GM.EntityFramework

A DDD + EF Core toolkit for .NET. This meta-package bundles GM.EntityFramework.Domain and GM.EntityFramework.Persistence.

GM.Notifications.Domain

Notification domain model for GM.Notifications — the NotificationBase aggregate (status, retry, scheduling) and per-channel entities (email, SMS, WhatsApp, push, Slack) built on EF Core.

GM.OTP.Domain

Domain model for the GM.OTP stack: the OtpChallenge aggregate plus the code-generation, hashing, and clock abstractions. Part of the GM.OTP family.

GM.Identity.Domain

Identity domain model — users, roles, permissions, scopes, clients, sessions, and two-factor auth types — as EF Core entities for GM-based identity and access systems.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 282 7/30/2026
1.2.0 116 7/28/2026
1.1.0 138 7/2/2026
1.0.1 318 6/13/2025
1.0.0 259 5/4/2025