Table of Contents

Class Entity<TId>

Namespace
Compendium.Core.Domain.Primitives
Assembly
Compendium.Core.dll

Base class for all entities in the domain. Provides identity, timestamps, and business rule validation.

public abstract class Entity<TId> : IEquatable<Entity<TId>> where TId : notnull

Type Parameters

TId

The type of the entity identifier.

Inheritance
Entity<TId>
Implements
Derived
Inherited Members

Constructors

Entity(TId)

Initializes a new instance of the Entity<TId> class.

protected Entity(TId id)

Parameters

id TId

The entity identifier.

Properties

BrokenRules

Gets the collection of broken business rules.

public IReadOnlyCollection<IBusinessRule> BrokenRules { get; }

Property Value

IReadOnlyCollection<IBusinessRule>

CreatedAt

Gets the timestamp when the entity was created.

public DateTimeOffset CreatedAt { get; }

Property Value

DateTimeOffset

HasBrokenRules

Gets a value indicating whether the entity has any broken business rules.

public bool HasBrokenRules { get; }

Property Value

bool

Id

Gets the entity identifier.

public TId Id { get; }

Property Value

TId

IsTransient

Gets a value indicating whether this entity is transient (not yet persisted).

public virtual bool IsTransient { get; }

Property Value

bool

ModifiedAt

Gets the timestamp when the entity was last modified.

public DateTimeOffset ModifiedAt { get; }

Property Value

DateTimeOffset

Methods

CheckRule(IBusinessRule)

Checks a business rule and adds it to the broken rules collection if it's broken.

protected void CheckRule(IBusinessRule rule)

Parameters

rule IBusinessRule

The business rule to check.

Exceptions

BusinessRuleValidationException

Thrown when the rule is broken.

ClearBrokenRules()

Clears all broken business rules.

protected void ClearBrokenRules()

Equals(Entity<TId>?)

Determines whether the specified entity is equal to the current entity.

public bool Equals(Entity<TId>? other)

Parameters

other Entity<TId>

The entity to compare with the current entity.

Returns

bool

true if the specified entity is equal to the current entity; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to the current entity.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current entity.

Returns

bool

true if the specified object is equal to the current entity; otherwise, false.

GetHashCode()

Returns the hash code for this entity.

public override int GetHashCode()

Returns

int

A hash code for the current entity.

Touch()

Updates the modified timestamp.

protected void Touch()

Operators

operator ==(Entity<TId>?, Entity<TId>?)

Determines whether two entities are equal.

public static bool operator ==(Entity<TId>? left, Entity<TId>? right)

Parameters

left Entity<TId>

The first entity to compare.

right Entity<TId>

The second entity to compare.

Returns

bool

true if the entities are equal; otherwise, false.

operator !=(Entity<TId>?, Entity<TId>?)

Determines whether two entities are not equal.

public static bool operator !=(Entity<TId>? left, Entity<TId>? right)

Parameters

left Entity<TId>

The first entity to compare.

right Entity<TId>

The second entity to compare.

Returns

bool

true if the entities are not equal; otherwise, false.