Interface IEntityUpdater
This is the core context class used for updating all data in the LemonEdge platform, regardless if the context is executing directly connected to the database, or across a web service
This context is always provided within UI and Context APIs, ensuring you can always access data wherever it is needed from a view, command, server running task or elsewhere
Inherited Members
Namespace: LemonEdge.Core
Assembly: API.dll
Syntax
public interface IEntityUpdater : IEntityRetriever, IDisposable
Remarks
This allows you to log changes against the context which are stored and recorded.
When you are ready you can save all the changes as one complete batch transaction
Properties
GetCustomFunctions
Returns a set of custom functions that can be run against this context taking into account any current changes it may have
Declaration
ICustomFunctions GetCustomFunctions { get; }
Property Value
| Type | Description |
|---|---|
| ICustomFunctions |
HasChanges
Indicates that this context has changes logged against it that haven't been committed yet
Declaration
bool HasChanges { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
IsSaving
Indicates the context is currently busy processing a Save operation and can not be queried or commit another Save at the same time
Declaration
bool IsSaving { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Processors
An enumeration of all processors that are active with this context. Those inheriting from IBaseDataSetProcessorWithDBSave will be called as part of the save process
Declaration
IEnumerable<IBaseDataSetProcessor> Processors { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<IBaseDataSetProcessor> |
Methods
AddSaveDateTimeStampHandler(Action<DateTimeOffset>)
When the transactional save is executed all records are stamped with the same lastupdated date time This provides the lastupdated time stamp that will be used before the items are saved in the transaction. You can use this to provide items handled with custom processes the same datetime stamp too. On a client connected to a service, this does nothing. On a direct db connection through client or webservice this is called by the system.
Declaration
void AddSaveDateTimeStampHandler(Action<DateTimeOffset> commitDateHandler)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Action<System.DateTimeOffset> | commitDateHandler |
ClearChange(IBaseEntity)
Clears log in this context that the specified item has pending changes to be saved
Declaration
void ClearChange(IBaseEntity item)
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | item | The item to clear from the log in this context that it has pending changes |
ClearChanges()
Clears all pending logged changes in this context.
Declaration
void ClearChanges()
CreateProcessor(ServerTaskAttribute)
Creates the task processor ITaskProcessor for the specified ServerTaskAttribute. If the task processor inherits from API.Processors.IBaseDataSetProcessor, it is added to the processor collection for this updater and will be run as part of the save process if it inherits IBaseDataSetProcessorWithDBSave
Declaration
ITaskProcessor CreateProcessor(ServerTaskAttribute forTaskType)
Parameters
| Type | Name | Description |
|---|---|---|
| ServerTaskAttribute | forTaskType | Returns the ITaskProcessor associated with the specified |
Returns
| Type | Description |
|---|---|
| ITaskProcessor | The task processor ITaskProcessor for the specified ServerTaskAttribute. |
GetChange(IBaseEntity)
Returns the type of change this context currently is recording against the specified item
Declaration
EntityOperation GetChange(IBaseEntity item)
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | item | The item this context has a change recorded for |
Returns
| Type | Description |
|---|---|
| EntityOperation | The type of change this context currently is recording against the specified |
GetChanges(EntityOperation, Type)
Returns an enumerations of all current changes of a particular change type and for am optional specified type of item (changeType)
Declaration
IEnumerable<IBaseEntity> GetChanges(EntityOperation type, Type changeType = null)
Parameters
| Type | Name | Description |
|---|---|---|
| EntityOperation | type | The type of change we want items returned for; Insert, Update or Deletes |
| System.Type | changeType | Optionally only return changed items that are of this type |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<IBaseEntity> | An enumerations of all current changes of a particular change |
GetChanges<T>(EntityOperation, Func<T, Boolean>)
Returns an enumerations of all current changes of a particular type (either the interface or class type works) held in the context.
This allows you to specify the type of change and an optional filter for the changes
Declaration
IEnumerable<T> GetChanges<T>(EntityOperation type, Func<T, bool> filter = null)
where T : IBaseEntity
Parameters
| Type | Name | Description |
|---|---|---|
| EntityOperation | type | The type of operation you want to see changes for: Insert, Update or Deletes |
| System.Func<T, System.Boolean> | filter | An optional filter which will filter the changes returned |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<T> | An enumerations of all current changes of a particular type (either the interface or class type works) held in the context. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of items you want to see any current changes for. This can be an interface or class type. |
GetChanges<T>(Func<T, Boolean>)
Returns an enumeration of all current changes of a particular type T (either the interface or class type works) along with the associated change type, held in the context
Declaration
IEnumerable<(EntityOperation Type, T Item)> GetChanges<T>(Func<T, bool> filter = null)
where T : IBaseEntity
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<T, System.Boolean> | filter | An optional filter which will filter the changes returned |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerable<System.ValueTuple<EntityOperation, T>> | An enumeration of all current changes of a particular type |
Type Parameters
| Name | Description |
|---|---|
| T | The type of items you want to see any current changes for. This can be an interface or class type. |
GetDefaultProcessor(IBaseEntity)
Returns the default processor for the specified forItem.
If the item is a member of an existing instance of the processor already that instance is returned by the context. If it is not then a new processor is created, the item added to it, and the processor returned
Declaration
IBaseDataSetProcessor GetDefaultProcessor(IBaseEntity forItem)
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | forItem | The item that the system finds the default processor for |
Returns
| Type | Description |
|---|---|
| IBaseDataSetProcessor | The default processor for the specified |
GetProcessor<T>(IBaseEntity)
Returns the processor of type T for the specified forItem.
If the item is a member of an existing instance of the processor already that instance is returned by the context if it is of the correct type. If it is not then a new processor is created, the item added to it, and the processor returned
Declaration
T GetProcessor<T>(IBaseEntity forItem)
where T : IBaseDataSetProcessor
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | forItem | The item that the system finds the default processor for |
Returns
| Type | Description |
|---|---|
| T | The processor of type |
Type Parameters
| Name | Description |
|---|---|
| T | Forces to return this processor type, even if it is not standard processor for this object |
HasChange(IBaseEntity)
Indicates if the specified item is currently marked as having changes associated with it in this context
Declaration
bool HasChange(IBaseEntity item)
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | item | The item to check if it has been marked as changed in this context |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified |
HasChange(Type, Guid)
Indicates if the specified item (via its unique type and id) is currently marked as having changes associated with it in this context
Declaration
bool HasChange(Type type, Guid id)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | type | The type of item to find and check if it has been marked as changed in this context |
| System.Guid | id | The id of the item to find and check if it has been marked as changed in this context |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified item (found through its unique |
LogChange(IBaseEntity, EntityOperation)
Logs in this context that the specified item has been changed along with in what way it has been changed (Inserted, Updated or Deleted)
Declaration
void LogChange(IBaseEntity item, EntityOperation op)
Parameters
| Type | Name | Description |
|---|---|---|
| IBaseEntity | item | The actual item that has changes to be logged in this context |
| EntityOperation | op | The type of change recorded against this |
SaveChanges(CancellationToken, Boolean, DbTransaction)
Commits all pending changed logged against this context as one batch transaction to the database.
This first collects all changes and runs any custom processes that in turn may create new changes, such as cascade deletes or transactional logic
Next all changes are validated including running your custom validations (certain database validations are only performed on the services)
Finally all changes are verified for permissions, audited and committed as one transaction
If any failures are encountered thay are reported back and the whole transaction fails to save any changes
Declaration
Task<IEnumerable<IHasSaveProcessingTask>> SaveChanges(CancellationToken cancel = default(CancellationToken), bool bypassValidation = false, DbTransaction transaction = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.CancellationToken | cancel | A cancellation token allowing the save process to be cancelled |
| System.Boolean | bypassValidation | Indicates the validation should be bypassed if you know the data conforms to the validation rules. Such as if the system has created the changes. |
| System.Data.Common.DbTransaction | transaction | Runs the save process in the specified existing transaction |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<IHasSaveProcessingTask>> | A task indicating the completion of the save along with an enumeration of all items that were created during the save that have a task processing on the server associated with them |
TryGetChange(Type, Guid, out EntityOperation, out IBaseEntity)
Returns the change type and item for a specified entityType and id if it exists in the set of changes in this context
Declaration
bool TryGetChange(Type entityType, Guid id, out EntityOperation Type, out IBaseEntity Item)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | entityType | The type of entity we want to see if this context holds any changes for |
| System.Guid | id | The id f the specific entity we want to find the changes for |
| EntityOperation | Type | If the specified item of type |
| IBaseEntity | Item | If the specified item of type |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the specified item of type |