CSharpEssentials.Entity
6.5.2
dotnet add package CSharpEssentials.Entity --version 6.5.2
NuGet\Install-Package CSharpEssentials.Entity -Version 6.5.2
<PackageReference Include="CSharpEssentials.Entity" Version="6.5.2" />
<PackageVersion Include="CSharpEssentials.Entity" Version="6.5.2" />
<PackageReference Include="CSharpEssentials.Entity" />
paket add CSharpEssentials.Entity --version 6.5.2
#r "nuget: CSharpEssentials.Entity, 6.5.2"
#:package CSharpEssentials.Entity@6.5.2
#addin nuget:?package=CSharpEssentials.Entity&version=6.5.2
#tool nuget:?package=CSharpEssentials.Entity&version=6.5.2
CSharpEssentials.Entity
DDD foundation for .NET entities with auditing, soft deletion, and domain events.
Features
EntityBase<TId>: Typed IDs with creation and modification audit fields.EntityBaseis the same without an ID.SoftDeletableEntityBase<TId>: Soft delete withMarkAsDeleted,Restore, andMarkAsHardDeleted.SoftDeletableEntityBaseis the same without an ID.- Domain Events: Raise and clear events for outbox or dispatcher patterns.
- Event Timing: Control when events publish with
[DomainEventTiming]. - Interfaces:
IEntityBase,IEntityBase<TId>,ISoftDeletable,ICreationAudit,IModificationAuditandIDomainEventHolder(namespaceCSharpEssentials.Entity.Interfaces) for code that works with any entity.
Installation
dotnet add package CSharpEssentials.Entity
Usage
Basic Entity
using CSharpEssentials.Entity;
public class Product : EntityBase<Guid>
{
public Product(Guid id) => Id = id; // Id has a protected setter
public string Name { get; set; } = string.Empty;
}
var product = new Product(Guid.NewGuid()) { Name = "Laptop" };
product.SetCreatedInfo(DateTimeOffset.UtcNow, "system");
product.SetUpdatedInfo(DateTimeOffset.UtcNow, "admin");
Soft Deletable Entity
public class User : SoftDeletableEntityBase<Guid>
{
public string Name { get; set; } = string.Empty;
}
var user = new User();
user.MarkAsDeleted(DateTimeOffset.UtcNow, "Admin"); // IsDeleted, DeletedAt, DeletedBy
user.Restore(); // clears IsDeleted, DeletedAt, DeletedBy and IsHardDeleted
MarkAsHardDeleted() sets IsHardDeleted, which tells the EF Core AuditInterceptor to remove the row instead of converting the delete into a soft delete. The HardDelete() extension (on IEnumerable<T> where T : ISoftDeletable) marks every item. The audit properties (CreatedAt, CreatedBy, UpdatedAt, UpdatedBy, DeletedAt, DeletedBy) have private setters; set them with SetCreatedInfo, SetUpdatedInfo and MarkAsDeleted. SetCreatedInfo throws ArgumentOutOfRangeException for DateTimeOffset.MinValue.
Domain Events
public record OrderCreated(Guid OrderId) : IDomainEvent;
public class Order : EntityBase<Guid>
{
public void Create()
{
Id = Guid.NewGuid();
Raise(new OrderCreated(Id));
}
}
var order = new Order();
order.Create();
// Later (e.g., in EF Core SaveChanges)
foreach (var evt in order.DomainEvents)
{
// dispatch...
}
order.ClearDomainEvents();
DomainEvents returns a snapshot, so raising or clearing events while you loop over it is safe. The EF Core package collects the events of tracked entities and dispatches them; see CSharpEssentials.EntityFrameworkCore.
Event Timing
// AfterSave (default): published after the save
public record OrderCreatedEvent(Guid OrderId) : IDomainEvent;
// Published before the save; a handler that throws aborts it
[DomainEventTiming(DomainEventTiming.BeforeSave)]
public record OrderValidationEvent(Guid OrderId) : IDomainEvent;
The attribute only labels the event; CSharpEssentials.EntityFrameworkCore reads it. BaseDbContext with DispatchDomainEventsOnSaveChanges publishes AfterSave events once the save has succeeded. DomainEventInterceptor dispatches them inside SavingChanges, still before the database write, so that an outbox can store them in the same save.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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 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. net11.0 is compatible. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CSharpEssentials.Results (>= 6.5.2)
- CSharpEssentials.Time (>= 6.5.2)
- Microsoft.Bcl.TimeProvider (>= 8.0.0)
- System.Text.Json (>= 9.0.4)
-
net10.0
- CSharpEssentials.Results (>= 6.5.2)
- CSharpEssentials.Time (>= 6.5.2)
-
net11.0
- CSharpEssentials.Results (>= 6.5.2)
- CSharpEssentials.Time (>= 6.5.2)
-
net9.0
- CSharpEssentials.Results (>= 6.5.2)
- CSharpEssentials.Time (>= 6.5.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CSharpEssentials.Entity:
| Package | Downloads |
|---|---|
|
CSharpEssentials
A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles. |
|
|
CSharpEssentials.EntityFrameworkCore
Enhances Entity Framework Core with functional programming patterns and DDD-friendly features. Includes base entity classes, soft delete support, audit trails, query filters, optimistic concurrency, PostgreSQL integration, query performance monitoring, and domain event handling. Perfect for building maintainable and scalable data access layers in modern .NET applications. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.5.2 | 103 | 10/10/2026 |
| 6.5.1 | 108 | 10/10/2026 |
| 6.5.0 | 107 | 10/9/2026 |
| 6.4.0 | 108 | 10/9/2026 |
| 6.3.0 | 105 | 10/8/2026 |
| 6.2.0 | 125 | 10/8/2026 |
| 6.1.0 | 124 | 10/7/2026 |
| 6.0.0 | 132 | 10/7/2026 |
| 5.2.1 | 129 | 10/7/2026 |
| 5.2.0 | 115 | 10/7/2026 |
| 5.1.0 | 133 | 10/7/2026 |
| 5.0.0 | 133 | 10/6/2026 |
| 4.1.0 | 132 | 10/6/2026 |
| 4.0.0 | 132 | 10/5/2026 |
| 3.2.3 | 329 | 5/31/2026 |
| 3.2.2 | 182 | 5/31/2026 |
| 3.2.1 | 183 | 5/31/2026 |
| 3.2.0 | 187 | 5/30/2026 |
| 3.1.0 | 189 | 5/27/2026 |
| 3.0.8 | 181 | 5/20/2026 |