Database ExtensionsDelete EntityTEntity Method
Delete the given entity 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 int DeleteEntity<TEntity>(
this DbContext dataContext,
TEntity entity
)
VB
<ExtensionAttribute>
Public Shared Function DeleteEntity(Of TEntity) (
dataContext As DbContext,
entity As TEntity
) As IntegerC++
public:
[ExtensionAttribute]
generic<typename TEntity>
static int DeleteEntity(
DbContext^ dataContext,
TEntity entity
)F#
[<ExtensionAttribute>]
static member DeleteEntity :
dataContext : DbContext *
entity : 'TEntity -> int Parameters
- dataContext DbContext
- The data context to use when deleting the entity
- entity TEntity
- The entity to delete
Type Parameters
- TEntity
- The entity type to delete
Return Value
Int32The 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 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.
Example
C#
using var dataContext = new MyDbContext();
dataContext.DeleteEntity(watchListItem);