public static Task<int> DeleteEntityAsync<TEntity>(
this DbContext dataContext,
TEntity entity,
CancellationToken cancellationToken = default
)
<ExtensionAttribute>
Public Shared Function DeleteEntityAsync(Of TEntity) (
dataContext As DbContext,
entity As TEntity,
Optional cancellationToken As CancellationToken = Nothing
) As Task(Of Integer)public:
[ExtensionAttribute]
generic<typename TEntity>
static Task<int>^ DeleteEntityAsync(
DbContext^ dataContext,
TEntity entity,
CancellationToken cancellationToken = CancellationToken()
)[<ExtensionAttribute>]
static member DeleteEntityAsync :
dataContext : DbContext *
entity : 'TEntity *
?cancellationToken : CancellationToken
(* Defaults:
let _cancellationToken = defaultArg cancellationToken new CancellationToken()
*)
-> Task<int> The stored procedure name is determined by looking for the DeleteEntityStoredProcedureAttribute on the entity type. The stored procedure must have one or more parameters representing the key columns on the entity type identified with a PrimaryKeyAttribute or one or more properties with a KeyAttribute or defined by the data context. It should not return a value or a result set. All parameters are input only.
If the connection is not in an open state, it is opened temporarily while deleting the entity. If change tracking is enabled on the data context and the entity its state will be set to unattached.
using var dataContext = new MyDbContext();
await dataContext.DeleteEntityAsync(watchListItem);