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.API.Core.Data
Assembly: LemonEdge.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
Cache
The cache being used for the updating context.
Declaration
IReadOnlyCache Cache { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCache |
EntityCreator
The IEntityCreator for creating new entities.
Declaration
IEntityCreator EntityCreator { get; }
Property Value
Type | Description |
---|---|
IEntityCreator |
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 |
---|---|
bool |
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 |
---|---|
bool |
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 |
---|---|
IEnumerable<IBaseDataSetProcessor> |
Methods
AddPendingExistingExtendedItem(IBaseEntity, Guid)
Adds the specified pending item (that exists but could be updated) to a pending list on the context. Any changes mean the item is removed from pending and automatically added to logchange. This is used for extended items in views, those items are created but a change isn't logged for new items unless a user makes a propertty change. Also this ensures the same loaded item is used across multiple possible views of it. This also returns the actual pending instance to use for that extended item id incase another thread/view has already added one to use first
Declaration
IBaseEntity AddPendingExistingExtendedItem(IBaseEntity pendingItem, Guid extendedItemID)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | pendingItem | The pending item to add to the context to be logged as a change if any property changes |
Guid | extendedItemID | The parent id of the type the item is extending |
Returns
Type | Description |
---|---|
IBaseEntity |
AddPendingExtendedItem(IBaseEntity, Guid)
Adds the specified pending item (that is newly created) to a pending list on the context. Any changes mean the item is removed from pending and automatically added to logchange. This is used for extended items in views, those items are created but a change isn't logged for new items unless a user makes a propertty change This also returns the actual new pending instance to use for that extended item id incase another thread/view has already added one to use first
Declaration
IBaseEntity AddPendingExtendedItem(IBaseEntity pendingItem, Guid extendedItemID)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | pendingItem | The pending item to add to the context to be logged as a change if any property changes |
Guid | extendedItemID | The parent id of the type the item is extending |
Returns
Type | Description |
---|---|
IBaseEntity |
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 |
---|---|---|
Action<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()
CreateNew()
Creates a new entityupdater in the same way this one was created
Declaration
Task<IEntityUpdater> CreateNew()
Returns
Type | Description |
---|---|
Task<IEntityUpdater> |
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. |
GetAllChanges()
Returns all current changes in the context
Declaration
(List<IBaseEntity> NewItems, List<IBaseEntity> UpdatedItems, List<IBaseEntity> DeletedItems) GetAllChanges()
Returns
Type | Description |
---|---|
(List<IBaseEntity> NewItems, List<IBaseEntity> UpdatedItems, List<IBaseEntity> DeletedItems) |
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 enumeration 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 |
Type | changeType | Optionally only return changed items that are of this type |
Returns
Type | Description |
---|---|
IEnumerable<IBaseEntity> | An enumeration of all current changes of a particular change |
GetChanges<T>(EntityOperation, Func<T, bool>)
Returns an enumeration 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 |
Func<T, bool> | filter | An optional filter which will filter the changes returned |
Returns
Type | Description |
---|---|
IEnumerable<T> | An enumeration 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, bool>)
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 |
---|---|---|
Func<T, bool> | filter | An optional filter which will filter the changes returned |
Returns
Type | Description |
---|---|
IEnumerable<(EntityOperation Type, T Item)> | 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 |
GetOrAddPendedExtendedItem(EntityDescriptor, Guid)
Retrieves the specified pending item that has been previously added, or creates a new one, adds that, and returns it.
Declaration
Task<(IBaseEntity Item, EntityOperation Operation)> GetOrAddPendedExtendedItem(EntityDescriptor extendedType, Guid extendedItemID)
Parameters
Type | Name | Description |
---|---|---|
EntityDescriptor | extendedType | The descriptor for the extended item type |
Guid | extendedItemID | The id of the item with the extended type |
Returns
Type | Description |
---|---|
Task<(IBaseEntity Item, EntityOperation Operation)> |
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 |
---|---|
bool | 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 |
---|---|---|
Type | type | The type of item to find and check if it has been marked as changed in this context |
Guid | id | The id of the item to find and check if it has been marked as changed in this context |
Returns
Type | Description |
---|---|
bool | 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, bool, bool, DbTransaction, bool)
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 that are reported back and the whole transaction fails to save any changes
Declaration
Task<(IEnumerable<IHasSaveProcessingTask> createdTasks, IEnumerable<Guid> newTaskIDs)> SaveChanges(CancellationToken cancel = default, bool bypassValidation = false, bool bypassProcessor = false, DbTransaction transaction = null, bool validateDeleteOnImport = false)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancel | A cancellation token allowing the save process to be cancelled |
bool | 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. Only works directly connected to the database. |
bool | bypassProcessor | Indicates the processors should be bypassed if you know the data conforms to the validation rules. Such as if the system has created the changes. Only works directly connected to the database. |
DbTransaction | transaction | Runs the save process in the specified existing transaction |
bool | validateDeleteOnImport | Indicates the validation should not bypass validation rules on importing delete item. Only works directly connected to the database. |
Returns
Type | Description |
---|---|
Task<(IEnumerable<IHasSaveProcessingTask> createdTasks, IEnumerable<Guid> newTaskIDs)> | 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 |
---|---|---|
Type | entityType | The type of entity we want to see if this context holds any changes for |
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 |
---|---|
bool | True if the specified item of type |