Compartilhar via


DbContext.Remove Method

Definition

Overloads

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)

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

Remove(Object)

Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs

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

public virtual Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry Remove (object entity);
abstract member Remove : obj -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry
override this.Remove : obj -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry
Public Overridable Function Remove (entity As Object) As EntityEntry

Parameters

entity
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.

Use State to set the state of only a single entity.

See EF Core change tracking for more information and examples.

Applies to

Remove<TEntity>(TEntity)

Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs
Source:
DbContext.cs

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

public virtual Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<TEntity> Remove<TEntity> (TEntity entity) where TEntity : class;
abstract member Remove : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)> (requires 'Entity : null)
override this.Remove : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)> (requires 'Entity : null)
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

The entity to remove.

Returns

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.

Use State to set the state of only a single entity.

See EF Core change tracking for more information and examples.

Applies to