Table of Contents

Class Entity<TId>

Namespace
KYS.EFCore.Library
Assembly
KYS.EFCore.Library.dll

Base class for domain entities, which are identified by their Id rather than by their values, and which can raise domain events.

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

Type Parameters

TId

The type of the entity identifier.

Inheritance
Entity<TId>
Implements
Inherited Members

Properties

DomainEvents

Gets the domain events raised by this entity, or null if none have been added yet.

public List<INotification> DomainEvents { get; }

Property Value

List<INotification>

Id

Gets or sets (in derived classes) the identifier of the entity.

public TId Id { get; protected set; }

Property Value

TId

Methods

AddDomainEvent(INotification)

Adds a domain event to DomainEvents.

public void AddDomainEvent(INotification eventItem)

Parameters

eventItem INotification

The domain event to add.

ClearDomainEvents()

Removes all domain events from DomainEvents, typically after they have been dispatched.

public void ClearDomainEvents()

Equals(Entity<TId>)

Determines whether the specified entity is equal to this entity.

Two entities are equal when they are the same instance, or when they are of the same type, neither is transient, and they have the same Id.

public virtual bool Equals(Entity<TId> other)

Parameters

other Entity<TId>

The entity to compare with this entity.

Returns

bool

true if the entities are equal; otherwise false.

Equals(object)

Determines whether the specified object is an Entity<TId> equal to this entity.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with this entity.

Returns

bool

true if the objects are equal; otherwise false.

GetHashCode()

Returns a hash code for this entity.

public override int GetHashCode()

Returns

int

A hash code for the current entity.

IsTransient()

Determines whether the entity has not been assigned an identifier yet (e.g. it has not been persisted).

public bool IsTransient()

Returns

bool

true if Id equals the default value of TId; otherwise false.

RemoveDomainEvent(INotification)

Removes a domain event from DomainEvents.

public void RemoveDomainEvent(INotification eventItem)

Parameters

eventItem INotification

The domain event to remove.

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 both are null or 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.