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

WriteEntity<TKey>

WriteEntity<TKey> inherits from CoreEntity<TKey> and represents mutable domain and data entities. It provides timestamp tracking for both initial creation (CreatedAt) and subsequent modifications (LastModifiedAt).

This class is the standard, recommended starting point for general-purpose entities in your application (products, customers, orders, categories) that can be created and edited over time.

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.Defined in WriteEntity<TKey>
LastModifiedAtDateTime?Gets or sets the last modification timestamp of the entity.Defined in WriteEntity<TKey>
Nullable LastModifiedAt

LastModifiedAt is a nullable DateTime?. When an entity is first created, this property is null. It is populated with the current timestamp whenever the entity is subsequently updated.

Class Definition​

using System;

namespace RA.Utilities.Data.Entities;

/// <summary>
/// Base class for writable entities that track creation and modification timestamps,
/// inheriting the unique identifier from <see cref="CoreEntity{TKey}"/>.
/// </summary>
/// <typeparam name="TKey">The type of the unique identifier.</typeparam>
public abstract class WriteEntity<TKey> : CoreEntity<TKey>
{
/// <summary>
/// Gets or sets the creation timestamp of the entity.
/// </summary>
public DateTime CreatedAt { get; set; }

/// <summary>
/// Gets or sets the last modification timestamp of the entity.
/// </summary>
public DateTime? LastModifiedAt { get; set; }
}

Role in the Entity Hierarchy​

WriteEntity<TKey> serves as the parent class for more specialized lifecycle entities:

WriteEntity<TKey> (CreatedAt, LastModifiedAt)
├── SoftDeleteEntity<TKey> (adds IsDeleted)
└── AuditableBaseEntity<TKey> (adds CreatedBy, LastModifiedBy)

Usage Example​

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

namespace MyApp.Domain.Entities;

public class Product : WriteEntity<Guid>
{
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public decimal Price { get; set; }
}

Resulting Structure​

When you create an instance of Product, it possesses the following properties:

PropertyTypeDescriptionOrigin
IdGuidUnique entity identifierInherited from CoreEntity<Guid>
CreatedAtDateTimeEntity creation timestampInherited from WriteEntity<Guid>
LastModifiedAtDateTime?Entity modification timestamp (null until updated)Inherited from WriteEntity<Guid>
NamestringName of the productDefined in Product
Descriptionstring?Optional product descriptionDefined in Product
PricedecimalUnit priceDefined in Product