DbContext.Remove<TEntity> DbContext.Remove(Of TEntity) Method

Definition

Overloads

Remove<TEntity>(TEntity) Remove(Of TEntity)(TEntity)

Begins tracking the given entity in the Deleted state such that it will be removed from the database when SaveChanges() is called.

Remove(Object) Remove(Object)

Begins tracking the given entity in the Deleted state such that it will be removed from the database when SaveChanges() is called.

Remove<TEntity>(TEntity) Remove(Of TEntity)(TEntity)

Begins tracking the given entity in the Deleted state such that it will be removed from the database when SaveChanges() is called.

public virtual EntityEntry<TEntity> Remove<TEntity>(TEntity entity)where TEntity : class
Public Overridable Function Remove(Of TEntity As Class)(entity As TEntity) As EntityEntry(Of TEntity)

Type Parameters

TEntity

The type of the entity.

Parameters

entity
TEntity TEntity

The entity to remove.

Returns

EntityEntry<TEntity> EntityEntry(Of TEntity)

The EntityEntry<TEntity> for the entity. The entry provides access to change tracking information and operations for the entity.

Remarks

If the entity is already tracked in the Added state then the context will stop tracking the entity (rather than marking it as Deleted) since the entity was previously added to the context and does not exist in the database.

Any other reachable entities that are not already being tracked will be tracked in the same way that they would be if Attach<TEntity>(TEntity) was called before calling this method. This allows any cascading actions to be applied when SaveChanges() is called.

Remove(Object) Remove(Object)

Begins tracking the given entity in the Deleted state such that it will be removed from the database when SaveChanges() is called.

public virtual EntityEntry Remove(object entity)
Public Overridable Function Remove(entity As Object) As EntityEntry

Parameters

entity
System.Object System.Object

The entity to remove.

Returns

The EntityEntry for the entity. The entry provides access to change tracking information and operations for the entity.

Remarks

If the entity is already tracked in the Added state then the context will stop tracking the entity (rather than marking it as Deleted) since the entity was previously added to the context and does not exist in the database.

Any other reachable entities that are not already being tracked will be tracked in the same way that they would be if Attach(Object) was called before calling this method. This allows any cascading actions to be applied when SaveChanges() is called.