DatabaseExtensionsSubmitChangesAsyncTEntity(DbContext, FuncEntityEntryTEntity, TaskBoolean, FuncEntityEntryTEntity, TaskBoolean, FuncEntityEntryTEntity, TaskBoolean, CancellationToken) 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.
Namespace: EWSoftware.EntityFrameworkAssembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
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
<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 Task
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()
)
[<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 INotifyPropertyChanged
- 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
- TEntity
- The entity type for which to submit changes
TaskA task representing the asynchronous operation.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).
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.
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;
});
}