DKNet.EfCore.Abstractions 9.0.33

dotnet add package DKNet.EfCore.Abstractions --version 9.0.33
                    
NuGet\Install-Package DKNet.EfCore.Abstractions -Version 9.0.33
                    
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.33" />
                    
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.33" />
                    
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.33
                    
#r "nuget: DKNet.EfCore.Abstractions, 9.0.33"
                    
#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.33
                    
#: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.33
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.EfCore.Abstractions&version=9.0.33
                    
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 (3)

Showing the top 3 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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.33 0 9/21/2025
9.0.32 0 9/21/2025
9.0.31 203 9/19/2025
9.0.30 210 9/18/2025
9.0.29 216 9/18/2025
9.0.28 236 9/17/2025
9.0.27 229 9/17/2025
9.0.26 242 9/16/2025
9.0.25 226 9/15/2025
9.0.24 217 9/15/2025
9.0.23 126 9/6/2025
9.0.22 172 9/3/2025
9.0.21 144 9/1/2025
9.0.20 177 7/15/2025
9.0.19 169 7/14/2025
9.0.18 168 7/14/2025
9.0.17 167 7/14/2025
9.0.16 150 7/11/2025
9.0.15 151 7/11/2025
9.0.14 149 7/11/2025
9.0.13 157 7/11/2025
9.0.12 172 7/8/2025
9.0.11 169 7/8/2025
9.0.10 168 7/7/2025
9.0.9 167 7/2/2025
9.0.8 166 7/2/2025
9.0.7 176 7/1/2025
9.0.6 172 6/30/2025
9.0.5 171 6/24/2025
9.0.4 171 6/24/2025
9.0.3 180 6/23/2025
9.0.2 173 6/23/2025
9.0.1 179 6/23/2025