Skip to main content
Namespace: RA.Utilities.Data.Entities

AuditableBaseEntity<TKey>

AuditableBaseEntity<TKey> inherits from WriteEntity<TKey> and adds user auditing capabilities to your data models.

While WriteEntity<TKey> tracks when a record was created or modified (CreatedAt, LastModifiedAt), AuditableBaseEntity<TKey> also tracks who performed those actions (CreatedBy, LastModifiedBy). This provides full accountability for security, compliance, and enterprise audit requirements.

Type Parameters​

ParameterDescription
TKeyThe data type of the entity's primary key identifier.

Properties​

PropertyTypeDescriptionSource
IdTKeyThe unique identifier for the entity.Inherited from CoreEntity<TKey>
CreatedAtDateTimeGets or sets the creation timestamp of the entity.Inherited from WriteEntity<TKey>
LastModifiedAtDateTime?Gets or sets the last modification timestamp of the entity.Inherited from WriteEntity<TKey>
CreatedBystring?Gets or sets the identifier of the user who created the entity.Defined in AuditableBaseEntity<TKey>
LastModifiedBystring?Gets or sets the identifier of the user who last modified the entity.Defined in AuditableBaseEntity<TKey>
User Identifiers

The CreatedBy and LastModifiedBy fields are strings, allowing you to store usernames, user emails, subject claims (sub), or GUID user identifiers as appropriate for your authentication system.

Class Definition​

using System;

namespace RA.Utilities.Data.Entities;

/// <summary>
/// Base class for entities that track creation and modification user identifiers,
/// inheriting common properties from <see cref="WriteEntity{TKey}"/>.
/// </summary>
/// <typeparam name="TKey">The type of the unique identifier.</typeparam>
public abstract class AuditableBaseEntity<TKey> : WriteEntity<TKey>
{
/// <summary>
/// Gets or sets the identifier of the user who created the entity.
/// </summary>
public string? CreatedBy { get; set; }

/// <summary>
/// Gets or sets the identifier of the user who last modified the entity.
/// </summary>
public string? LastModifiedBy { get; set; }
}

Usage Example​

using System;
using RA.Utilities.Data.Entities;

namespace MyApp.Domain.Entities;

public class Order : AuditableBaseEntity<Guid>
{
public Guid CustomerId { get; set; }
public decimal TotalAmount { get; set; }
public string Status { get; set; } = "Pending";
}

Resulting Structure​

An instance of Order exposes the complete audit and identification trail:

PropertyTypeRoleOrigin
IdGuidPrimary keyInherited from CoreEntity<Guid>
CreatedAtDateTimeCreation timeInherited from WriteEntity<Guid>
LastModifiedAtDateTime?Update timeInherited from WriteEntity<Guid>
CreatedBystring?Creator identifierInherited from AuditableBaseEntity<Guid>
LastModifiedBystring?Modifier identifierInherited from AuditableBaseEntity<Guid>
CustomerIdGuidForeign keyDefined in Order
TotalAmountdecimalOrder amountDefined in Order
StatusstringOrder statusDefined in Order