DatabaseExtensionsSubmitChangesTEntity(DbContext, FuncEntityEntryTEntity, Boolean, FuncEntityEntryTEntity, Boolean, FuncEntityEntryTEntity, Boolean) Method

Submit all tracked add, update, and delete changes 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
public static void SubmitChanges<TEntity>(
	this DbContext dataContext,
	Func<EntityEntry<TEntity>, bool>? insert,
	Func<EntityEntry<TEntity>, bool>? update,
	Func<EntityEntry<TEntity>, bool>? delete
)
where TEntity : class, INotifyPropertyChanged

Parameters

dataContext  DbContext
The data context to use for the operations
insert  FuncEntityEntryTEntity, Boolean
The 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, Boolean
The 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, Boolean
The 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.

Type Parameters

TEntity
The entity type for which to submit changes

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.SubmitChanges<StateCode>(
        se =>
        {
            dataContext.spStateCodeAddUpdate(null, se.Entity.State, se.Entity.StateDesc);
            return true;
        },
        se =>
        {
            dataContext.spStateCodeAddUpdate((string?)se.OriginalValues[nameof(StateCode.State)],
                se.Entity.State, se.Entity.StateDesc);
            return true;
        },
        se =>
        {
            dataContext.spStateCodeDelete((string?)se.OriginalValues[nameof(StateCode.State)]);
            return true;
        });
}

See Also