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
TIdThe type of the entity identifier.
- Inheritance
-
Entity<TId>
- Implements
-
IEquatable<Entity<TId>>
- 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
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
eventItemINotificationThe 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
otherEntity<TId>The entity to compare with this entity.
Returns
Equals(object)
Determines whether the specified object is an Entity<TId> equal to this entity.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with this entity.
Returns
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
RemoveDomainEvent(INotification)
Removes a domain event from DomainEvents.
public void RemoveDomainEvent(INotification eventItem)
Parameters
eventItemINotificationThe 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
Returns
operator !=(Entity<TId>, Entity<TId>)
Determines whether two entities are not equal.
public static bool operator !=(Entity<TId> left, Entity<TId> right)