RCommon.Entities
2.4.1
dotnet add package RCommon.Entities --version 2.4.1
NuGet\Install-Package RCommon.Entities -Version 2.4.1
<PackageReference Include="RCommon.Entities" Version="2.4.1" />
<PackageVersion Include="RCommon.Entities" Version="2.4.1" />
<PackageReference Include="RCommon.Entities" />
paket add RCommon.Entities --version 2.4.1
#r "nuget: RCommon.Entities, 2.4.1"
#:package RCommon.Entities@2.4.1
#addin nuget:?package=RCommon.Entities&version=2.4.1
#tool nuget:?package=RCommon.Entities&version=2.4.1
RCommon.Entities
Domain entity base classes for the RCommon framework, providing a strongly-typed BusinessEntity<TKey> base with built-in transactional event tracking, auditing support via AuditedEntity, and an IEntityEventTracker that collects and emits entity events through the event routing infrastructure.
Features
BusinessEntityandBusinessEntity<TKey>abstract base classes with composite and single-key support- Built-in transactional (local) event accumulation on entities via
AddLocalEvent,RemoveLocalEvent, andClearLocalEvents - Entity-level event notifications (
TransactionalEventAdded,TransactionalEventRemoved,TransactionalEventsCleared) for observing event changes AuditedEntitybase classes that trackCreatedBy,DateCreated,LastModifiedBy, andDateLastModifiedwith flexible user typesITrackedEntityinterface for opting entities into event trackingIEntityEventTrackerandInMemoryEntityEventTrackerfor collecting entity events across object graphs and routing them throughIEventRouter- Soft delete --
ISoftDeleteopt-in interface for logical deletion (IsDeletedflag) instead of physical removal - Multitenancy --
IMultiTenantopt-in interface for tenant-scoped entities (TenantIdproperty) EntityNotFoundExceptionfor consistent "entity not found" error handling with type and ID context
Installation
dotnet add package RCommon.Entities
Usage
using RCommon.Entities;
using RCommon.Models.Events;
// Define a domain entity with a GUID key
public class Order : BusinessEntity<Guid>
{
public string ProductName { get; set; }
public int Quantity { get; set; }
public void Submit()
{
// Add a transactional event that will be emitted on persistence
AddLocalEvent(new OrderSubmittedEvent { OrderId = Id });
}
}
// Define an audited entity tracking who created/modified it
public class Invoice : AuditedEntity<Guid, string, string>
{
public decimal Amount { get; set; }
public string Currency { get; set; }
}
// Emit entity events through the event router
public class OrderService
{
private readonly IEntityEventTracker _eventTracker;
public OrderService(IEntityEventTracker eventTracker)
{
_eventTracker = eventTracker;
}
public async Task ProcessOrderAsync(Order order)
{
order.Submit();
_eventTracker.AddEntity(order);
await _eventTracker.EmitTransactionalEventsAsync();
}
}
Soft Delete
Implement ISoftDelete to opt an entity into logical deletion. Repositories will set IsDeleted = true and perform an UPDATE instead of a physical DELETE:
using RCommon.Entities;
public class Customer : BusinessEntity<int>, ISoftDelete
{
public string Name { get; set; }
public bool IsDeleted { get; set; }
}
// Soft delete — sets IsDeleted = true, performs UPDATE
await repository.DeleteAsync(customer, isSoftDelete: true);
// Physical delete — removes the record entirely
await repository.DeleteAsync(customer, isSoftDelete: false);
Entities implementing ISoftDelete are automatically filtered on read operations -- soft-deleted records are excluded from query results by default.
Multitenancy
Implement IMultiTenant to scope an entity to a specific tenant. Repositories will automatically stamp the TenantId on add operations and filter reads to only return records for the current tenant:
using RCommon.Entities;
public class Product : BusinessEntity<int>, IMultiTenant
{
public string Name { get; set; }
public string? TenantId { get; set; }
}
When both interfaces are combined, the entity supports soft delete and tenant isolation:
public class Invoice : BusinessEntity<Guid>, ISoftDelete, IMultiTenant
{
public decimal Amount { get; set; }
public bool IsDeleted { get; set; }
public string? TenantId { get; set; }
}
Key Types
| Type | Description |
|---|---|
IBusinessEntity |
Base entity interface with composite key support and local event collection |
IBusinessEntity<TKey> |
Entity interface with a single strongly-typed Id property |
BusinessEntity |
Abstract base class with transactional event tracking and entity equality |
BusinessEntity<TKey> |
Generic base class adding a typed primary key to BusinessEntity |
IAuditedEntity<TCreatedByUser, TLastModifiedByUser> |
Audit contract with created/modified user and timestamp properties |
AuditedEntity<TKey, TCreatedByUser, TLastModifiedByUser> |
Base class combining BusinessEntity<TKey> with full audit tracking |
ITrackedEntity |
Marks an entity as eligible for event tracking via AllowEventTracking |
IEntityEventTracker |
Collects tracked entities and emits their transactional events |
InMemoryEntityEventTracker |
In-memory implementation that traverses entity object graphs and routes events |
ISoftDelete |
Opt-in interface for soft delete; adds IsDeleted property for logical deletion |
IMultiTenant |
Opt-in interface for multitenancy; adds TenantId property for tenant scoping |
EntityNotFoundException |
Exception for when an expected entity does not exist, with type and ID context |
Documentation
For full documentation, visit rcommon.com.
Related Packages
- RCommon.Core - Foundation package with event bus, builder pattern, guards, and extensions
- RCommon.Models - Shared models for CQRS commands, queries, events, pagination, and execution results
License
Licensed under the Apache License, Version 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net10.0
- RCommon.Core (>= 2.4.1)
-
net8.0
- RCommon.Core (>= 2.4.1)
-
net9.0
- RCommon.Core (>= 2.4.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RCommon.Entities:
| Package | Downloads |
|---|---|
|
RCommon.Persistence
A cohesive set of infrastructure libraries for dotnet that utilizes abstractions for event handling, persistence, unit of work, mediator, distributed messaging, event bus, CQRS, email, and more |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.4.1 | 18 | 2/18/2026 |
| 2.3.2-alpha.0.3 | 22 | 2/18/2026 |
| 2.3.2-alpha.0.2 | 27 | 2/18/2026 |
| 2.3.2-alpha.0.1 | 55 | 2/9/2026 |
| 2.3.1 | 225 | 2/5/2026 |
| 2.3.0 | 215 | 2/3/2026 |
| 2.2.2-alpha.0.1 | 394 | 12/11/2025 |
| 2.2.1-alpha.0.2 | 131 | 10/24/2025 |
| 2.2.1-alpha.0.1 | 147 | 10/24/2025 |
| 2.1.11-alpha.0.2 | 121 | 10/24/2025 |
| 2.1.11-alpha.0.1 | 99 | 7/18/2025 |
| 2.1.10 | 392 | 7/17/2025 |
| 2.1.9-alpha.0.1 | 150 | 7/17/2025 |
| 2.1.2.4 | 335 | 5/21/2025 |
| 2.1.2.3 | 310 | 5/1/2025 |
| 2.1.2.2 | 614 | 1/23/2025 |
| 2.1.2.1 | 276 | 1/17/2025 |
| 2.1.2 | 267 | 1/17/2025 |
| 2.1.1.4 | 273 | 1/7/2025 |
| 0.0.0-alpha.0 | 149 | 7/17/2025 |