Database ExtensionsSubmit Changes AsyncTEntity(DbContext, FuncEntityEntryTEntity, TaskBoolean, FuncEntityEntryTEntity, TaskBoolean, FuncEntityEntryTEntity, TaskBoolean, Cancellation Token) Method
Submit all tracked add, update, and delete changes asynchronously for the given entity type using
supplied functions that allow for custom handling of the operations.
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
A task representing the asynchronous operation.
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static Task SubmitChangesAsync<TEntity>(
this DbContext dataContext,
Func<EntityEntry<TEntity>, Task<bool>>? insert,
Func<EntityEntry<TEntity>, Task<bool>>? update,
Func<EntityEntry<TEntity>, Task<bool>>? delete,
CancellationToken cancellationToken = default
)
where TEntity : class, INotifyPropertyChanged
VB
<ExtensionAttribute>
Public Shared Function SubmitChangesAsync(Of TEntity As {Class, INotifyPropertyChanged}) (
dataContext As DbContext,
insert As Func(Of EntityEntry(Of TEntity), Task(Of Boolean)),
update As Func(Of EntityEntry(Of TEntity), Task(Of Boolean)),
delete As Func(Of EntityEntry(Of TEntity), Task(Of Boolean)),
Optional cancellationToken As CancellationToken = Nothing
) As TaskC++
public:
[ExtensionAttribute]
generic<typename TEntity>
where TEntity : ref class, INotifyPropertyChanged
static Task^ SubmitChangesAsync(
DbContext^ dataContext,
Func<EntityEntry<TEntity>^, Task<bool>^>^ insert,
Func<EntityEntry<TEntity>^, Task<bool>^>^ update,
Func<EntityEntry<TEntity>^, Task<bool>^>^ delete,
CancellationToken cancellationToken = CancellationToken()
)F#
[<ExtensionAttribute>]
static member SubmitChangesAsync :
dataContext : DbContext *
insert : Func<EntityEntry<'TEntity>, Task<bool>> *
update : Func<EntityEntry<'TEntity>, Task<bool>> *
delete : Func<EntityEntry<'TEntity>, Task<bool>> *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> Task when 'TEntity : not struct and INotifyPropertyChangedParameters
- dataContext DbContext
- The data context to use for the operations
- insert FuncEntityEntryTEntity, TaskBoolean
- The asynchronous function to invoke to handle insertions. It is passed the entity change entry and should return true if the insertion was made or false if not. If null, the action is ignored.
- update FuncEntityEntryTEntity, TaskBoolean
- The asynchronous function to invoke to handle updates. It is passed the entity change entry and should return true if the update was made or false if not. If null, the action is ignored.
- delete FuncEntityEntryTEntity, TaskBoolean
- The asynchronous function to invoke to handle deletions. It is passed the entity change entry and should return true if the delete was made or false if not. If null, the action is ignored.
- cancellationToken CancellationToken (Optional)
- An optional cancellation token
Type Parameters
- TEntity
- The entity type for which to submit changes
Return Value
TaskA task representing the asynchronous operation.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type DbContext. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).Remarks
This will get the changed entities from the data context's change tracker and submit them
accordingly using the given functions. If the corresponding function returns true, the state of the
entity is updated to reflect that it is in an unchanged state after being added or updated or
detached if deleted. If the connection is not in an open state, it is opened temporarily while
performing the actions.
Example
C#
if(dataContext.HasChanges())
{
// Submit changes using stored procedure methods on the data context
dataContext.SubmitChangesAsync<StateCode>(
async se =>
{
await dataContext.spStateCodeAddUpdate(null, se.Entity.State, se.Entity.StateDesc);
return true;
},
async se =>
{
await dataContext.spStateCodeAddUpdate((string?)se.OriginalValues[nameof(StateCode.State)],
se.Entity.State, se.Entity.StateDesc);
return true;
},
async se =>
{
await dataContext.spStateCodeDelete((string?)se.OriginalValues[nameof(StateCode.State)]);
return true;
});
}