Database ExtensionsUpdate Entity AsyncTEntity Method
Update the given entity asynchronously using a stored procedure defined on the entity type
Definition
Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
The number of rows affected assuming the stored procedure is not using SET NOCOUNT ON
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
C#
public static Task<int> UpdateEntityAsync<TEntity>(
this DbContext dataContext,
TEntity entity,
CancellationToken cancellationToken = default
)
VB
<ExtensionAttribute>
Public Shared Function UpdateEntityAsync(Of TEntity) (
dataContext As DbContext,
entity As TEntity,
Optional cancellationToken As CancellationToken = Nothing
) As Task(Of Integer)C++
public:
[ExtensionAttribute]
generic<typename TEntity>
static Task<int>^ UpdateEntityAsync(
DbContext^ dataContext,
TEntity entity,
CancellationToken cancellationToken = CancellationToken()
)F#
[<ExtensionAttribute>]
static member UpdateEntityAsync :
dataContext : DbContext *
entity : 'TEntity *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> Task<int> Parameters
- dataContext DbContext
- The data context to use when updating the entity
- entity TEntity
- The entity to update
- cancellationToken CancellationToken (Optional)
- An optional cancellation token
Type Parameters
- TEntity
- The entity type to update
Return Value
TaskInt32The number of rows affected assuming the stored procedure is not using SET NOCOUNT ON
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
The stored procedure name is determined by looking for the UpdateEntityStoredProcedureAttribute on the entity type. The stored procedure must have parameters for each of the entity properties except those marked with the IgnoreAttribute for updates. It should not return a value or a result set. Parameters marked with the TimestampAttribute are defined as input/out parameters. All other parameters are input only.
If the connection is not in an open state, it is opened temporarily while updating the entity. If change tracking is enabled on the data context and the entity its state will be set to unchanged.
Example
C#
using var dataContext = new MyDbContext();
if(watchListItem.WatchID == 0)
await dataContext.InsertEntityAsync(watchListItem);
else
await dataContext.UpdateEntityAsync(watchListItem);