DKNet.EfCore.Abstractions 9.0.38

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

DKNet.EfCore.Abstractions

NuGet NuGet Downloads .NET License

Core abstractions and interfaces for Entity Framework Core applications implementing Domain-Driven Design (DDD) patterns. This package provides essential base classes, interfaces, and attributes for building robust data access layers with auditing, events, and entity management capabilities.

Features

  • Entity Base Classes: Generic entity base classes with flexible key types
  • Audit Interfaces: Built-in auditing capabilities with creation and modification tracking
  • Event Management: Domain event support for entities (IEventEntity)
  • Soft Delete Support: Soft deletion patterns for logical record removal
  • Concurrency Control: Optimistic concurrency control interfaces
  • Sequence Attributes: Database sequence generation for unique identifiers
  • Static Data Attributes: Marking entities for static/reference data
  • Ignore Entity Attributes: Control over entity discovery and mapping

Supported Frameworks

  • .NET 9.0+
  • Entity Framework Core 9.0+

Installation

Install via NuGet Package Manager:

dotnet add package DKNet.EfCore.Abstractions

Or via Package Manager Console:

Install-Package DKNet.EfCore.Abstractions

Quick Start

Basic Entity Implementation

using DKNet.EfCore.Abstractions.Entities;

public class Product : Entity<Guid>
{
    public Product(string name, decimal price, string createdBy) 
        : base(Guid.NewGuid(), createdBy)
    {
        Name = name;
        Price = price;
    }

    public string Name { get; private set; }
    public decimal Price { get; private set; }
    
    public void UpdatePrice(decimal newPrice, string updatedBy)
    {
        Price = newPrice;
        SetUpdatedBy(updatedBy);
    }
}

Auditable Entity

using DKNet.EfCore.Abstractions.Entities;

public class Customer : AuditEntity<int>
{
    public Customer(string name, string email, string createdBy) 
        : base(createdBy)
    {
        Name = name;
        Email = email;
    }

    public string Name { get; private set; }
    public string Email { get; private set; }
    
    // Inherits: CreatedBy, CreatedOn, UpdatedBy, UpdatedOn
}

Soft Deletable Entity

using DKNet.EfCore.Abstractions.Entities;

public class Document : Entity<Guid>, ISoftDeletableEntity
{
    public Document(string title, string createdBy) : base(Guid.NewGuid(), createdBy)
    {
        Title = title;
    }

    public string Title { get; private set; }
    public bool IsDeleted { get; private set; }
    public DateTimeOffset? DeletedOn { get; private set; }
    public string? DeletedBy { get; private set; }

    public void SoftDelete(string deletedBy)
    {
        IsDeleted = true;
        DeletedOn = DateTimeOffset.UtcNow;
        DeletedBy = deletedBy;
    }
}

Configuration

Entity Configuration with Attributes

using DKNet.EfCore.Abstractions.Attributes;

[StaticData] // Marks as reference/static data
public class Category : Entity<int>
{
    [Sequence(typeof(int))] // Auto-generate sequence values
    public int Order { get; set; }
    
    public string Name { get; set; }
}

[IgnoreEntity] // Exclude from EF discovery
public class TemporaryData
{
    public string Value { get; set; }
}

SQL Sequence Configuration

using DKNet.EfCore.Abstractions.Attributes;

public class Invoice : Entity<long>
{
    [SqlSequence("invoice_number_seq", Schema = "billing")]
    public long InvoiceNumber { get; set; }
    
    public decimal Amount { get; set; }
}

API Reference

Core Interfaces

  • IEntity<TKey> - Basic entity contract with generic key
  • IAuditedProperties - Auditing properties (CreatedBy, CreatedOn, etc.)
  • ISoftDeletableEntity - Soft deletion capabilities
  • IEventEntity - Domain event management
  • IConcurrencyEntity - Optimistic concurrency control

Base Classes

  • Entity<TKey> - Generic entity base with event support
  • AuditEntity<TKey> - Entity with full audit trail capabilities

Attributes

  • [Sequence(Type)] - Generate sequential values for fields
  • [SqlSequence(string)] - SQL-based sequence generation
  • [StaticData] - Mark entity as static/reference data
  • [IgnoreEntity] - Exclude entity from EF discovery

Advanced Usage

Domain Events with Entities

public class Order : Entity<Guid>
{
    public Order(string customerName, string createdBy) : base(Guid.NewGuid(), createdBy)
    {
        CustomerName = customerName;
        Status = OrderStatus.Pending;
        
        // Add domain event
        AddEvent(new OrderCreatedEvent(Id, customerName));
    }

    public string CustomerName { get; private set; }
    public OrderStatus Status { get; private set; }
    
    public void Complete(string updatedBy)
    {
        Status = OrderStatus.Completed;
        SetUpdatedBy(updatedBy);
        
        // Add domain event
        AddEvent(new OrderCompletedEvent(Id));
    }
}

public record OrderCreatedEvent(Guid OrderId, string CustomerName);
public record OrderCompletedEvent(Guid OrderId);

Custom Audit Implementation

public class CustomAuditEntity : Entity<Guid>, IAuditedProperties
{
    protected CustomAuditEntity(string createdBy) : base(Guid.NewGuid(), createdBy)
    {
        CreatedBy = createdBy;
        CreatedOn = DateTimeOffset.UtcNow;
    }

    public string CreatedBy { get; protected set; }
    public DateTimeOffset CreatedOn { get; protected set; }
    public string? UpdatedBy { get; protected set; }
    public DateTimeOffset? UpdatedOn { get; protected set; }

    protected void SetUpdatedBy(string updatedBy)
    {
        UpdatedBy = updatedBy;
        UpdatedOn = DateTimeOffset.UtcNow;
    }
}

Aggregate Root Pattern

public class AggregateRoot : Entity<Guid>
{
    protected AggregateRoot(string createdBy) : base(Guid.NewGuid(), createdBy)
    {
    }

    // Additional aggregate-specific behavior
    // Event management, invariant enforcement, etc.
}

Entity Lifecycle

The abstractions support full entity lifecycle management:

  1. Creation: Entities initialized with required audit information
  2. Modification: Automatic tracking of changes and updates
  3. Event Handling: Domain events queued and managed
  4. Soft Deletion: Logical removal without physical deletion
  5. Concurrency: Optimistic concurrency control support

Thread Safety

  • Entity instances are not thread-safe by design (following EF Core patterns)
  • Event collections are managed internally and should not be accessed concurrently
  • Use appropriate concurrency control mechanisms in your DbContext

Performance Considerations

  • Generic key types provide flexibility without boxing overhead
  • Event collections use efficient Collection<T> internally
  • Audit properties use DateTimeOffset for timezone-aware timestamps
  • Sequence attributes optimize database-generated values

Contributing

See the main CONTRIBUTING.md for guidelines on how to contribute to this project.

License

This project is licensed under the MIT License.


Part of the DKNet Framework - A comprehensive .NET framework for building modern, scalable applications.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (4)

Showing the top 4 NuGet packages that depend on DKNet.EfCore.Abstractions:

Package Downloads
DKNet.EfCore.Extensions

Package Description

DKNet.EfCore.Repos.Abstractions

Package Description

DKNet.EfCore.Events

Package Description

DKNet.EfCore.AuditLogs

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.5.9 0 10/13/2025
9.5.8 46 10/11/2025
9.5.7 63 10/10/2025
9.5.6 62 10/10/2025
9.5.5 74 10/10/2025
9.5.4 74 10/10/2025
9.5.3 197 10/8/2025
9.5.2 164 10/8/2025
9.5.1 243 10/7/2025
9.0.42 250 10/6/2025
9.0.41 264 10/2/2025
9.0.40 253 9/27/2025
9.0.39 233 9/26/2025
9.0.38 260 9/24/2025
9.0.37 241 9/23/2025
9.0.36 299 9/23/2025
9.0.35 245 9/23/2025
9.0.34 262 9/23/2025
9.0.33 247 9/21/2025
9.0.32 242 9/21/2025
9.0.31 362 9/19/2025
9.0.30 362 9/18/2025
9.0.29 352 9/18/2025
9.0.28 371 9/17/2025
9.0.27 373 9/17/2025
9.0.26 357 9/16/2025
9.0.25 312 9/15/2025
9.0.24 300 9/15/2025
9.0.23 202 9/6/2025
9.0.22 235 9/3/2025
9.0.21 212 9/1/2025
9.0.20 237 7/15/2025
9.0.19 229 7/14/2025
9.0.18 240 7/14/2025
9.0.17 220 7/14/2025
9.0.16 195 7/11/2025
9.0.15 212 7/11/2025
9.0.14 209 7/11/2025
9.0.13 220 7/11/2025
9.0.12 228 7/8/2025
9.0.11 217 7/8/2025
9.0.10 220 7/7/2025
9.0.9 218 7/2/2025
9.0.8 204 7/2/2025
9.0.7 230 7/1/2025
9.0.6 229 6/30/2025
9.0.5 228 6/24/2025
9.0.4 231 6/24/2025
9.0.3 222 6/23/2025
9.0.2 227 6/23/2025
9.0.1 236 6/23/2025