Class EntityBase<TProperties, TReport>
Base class for all entities, wrapping an EntityKernel to provide core properties and lifecycle management.
public abstract class EntityBase<TProperties, TReport> : IEntity, IHasChanges where TProperties : IEntityProperties
Type Parameters
TPropertiesTReport
- Inheritance
-
EntityBase<TProperties, TReport>
- Implements
- Inherited Members
- Extension Methods
Constructors
EntityBase(EntityPropertiesFactory<TProperties, TReport>)
[Obsolete("not safe; does not set _Kernel until Init() is later called!")]
protected EntityBase(EntityPropertiesFactory<TProperties, TReport> propsFactory)
Parameters
propsFactoryEntityPropertiesFactory<TProperties, TReport>
EntityBase(IEntityInfo, IEntityContext, IEntityInitialiser, EntityPropertiesFactory<TProperties, TReport>)
protected EntityBase(IEntityInfo metadata, IEntityContext context, IEntityInitialiser initialiser, EntityPropertiesFactory<TProperties, TReport> propsFactory)
Parameters
metadataIEntityInfocontextIEntityContextinitialiserIEntityInitialiserpropsFactoryEntityPropertiesFactory<TProperties, TReport>
Properties
Context
An entity's unit of work for saving. Entities in a graph must be in the same context.
[JsonIgnore]
public IEntityContext Context { get; }
Property Value
ID
Unique identifier of this entity
public Guid ID { get; }
Property Value
Remarks
useful in generic queries
Kernel
The entity's dynamic kernel.
[JsonIgnore]
public EntityKernel Kernel { get; }
Property Value
Logger
protected ILogger Logger { get; }
Property Value
Properties
The entity's dynamic propertyobjects.
[JsonIgnore]
public TProperties Properties { get; }
Property Value
- TProperties
Services
protected IServices Services { get; }
Property Value
Text
Textual description of the entity
public string Text { get; }
Property Value
Remarks
useful in generic queries
report
Null-safe stringified version of the entity for reports and descriptions.
[JsonIgnore]
public TReport report { get; }
Property Value
- TReport
Methods
Delete()
Mark the entity for deletion when next saved
[Obsolete("Non-async delete is deprecated because it tends to leave entities in an unsaveable state.")]
public void Delete()
DeleteAndCascadeAsync(CancellationToken?)
deletes an entity as well as its owned (Value) entities, removing it from unowned (Lookup) relationships
public Task DeleteAndCascadeAsync(CancellationToken? cancellationToken = null)
Parameters
cancellationTokenCancellationToken?
Returns
DeleteAndPruneAsync(CancellationToken?)
Mark the entity for deletion when next saved, removing it from all relationships first
public Task DeleteAndPruneAsync(CancellationToken? cancellationToken = null)
Parameters
cancellationTokenCancellationToken?
Returns
HasChanges()
true if the current value differs from its original
public bool HasChanges()
Returns
Init(IEntityInfo, IEntityContext, IEntityInitialiser)
protected void Init(IEntityInfo metadata, IEntityContext context, IEntityInitialiser initialiser)
Parameters
metadataIEntityInfocontextIEntityContextinitialiserIEntityInitialiser
IsCalculated()
protected virtual bool IsCalculated()
Returns
MarkUnchanged()
update original data so that it's no longer considered changed
public void MarkUnchanged()
NeedsSave()
true if the value has non-derived changes, ones made deliberately by a user or business logic
public bool NeedsSave()
Returns
OnCreated()
protected virtual void OnCreated()
OnLoaded()
protected virtual void OnLoaded()
OnSaved()
protected virtual void OnSaved()
OnSavedAsync()
protected virtual Task OnSavedAsync()
Returns
OnSaving()
protected virtual void OnSaving()
OnSavingAsync()
protected virtual Task OnSavingAsync()
Returns
SaveAsync(CancellationToken?)
Save the graph rooted at this entity to the data store
public Task SaveAsync(CancellationToken? cancellationToken = null)
Parameters
cancellationTokenCancellationToken?
Returns
ToString()
Returns a string that represents the current object.
public override sealed string ToString()
Returns
- string
A string that represents the current object.