DbSet<TEntity>.Remove(TEntity) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 entity);
abstract member Remove : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)>
override this.Remove : 'Entity -> Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<'Entity (requires 'Entity : null)>
Public Overridable Function Remove (entity As TEntity) As EntityEntry(Of TEntity)
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) 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.