Share via


DbSet<TEntity>.RemoveRange Method

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see msdn.com/data/ef.]

Removes the given collection of entities from the context underlying the set with each entity being put into the Deleted state such that it will be deleted from the database when SaveChanges is called.

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

Syntax

'Declaration
Public Overridable Function RemoveRange ( _
    entities As IEnumerable(Of TEntity) _
) As IEnumerable(Of TEntity)
'Usage
Dim instance As DbSet 
Dim entities As IEnumerable(Of TEntity)
Dim returnValue As IEnumerable(Of TEntity)

returnValue = instance.RemoveRange(entities)
public virtual IEnumerable<TEntity> RemoveRange(
    IEnumerable<TEntity> entities
)
public:
virtual IEnumerable<TEntity>^ RemoveRange(
    IEnumerable<TEntity>^ entities
)
abstract RemoveRange : 
        entities:IEnumerable<'TEntity> -> IEnumerable<'TEntity> 
override RemoveRange : 
        entities:IEnumerable<'TEntity> -> IEnumerable<'TEntity> 
public function RemoveRange(
    entities : IEnumerable<TEntity>
) : IEnumerable<TEntity>

Parameters

Return Value

Type: System.Collections.Generic.IEnumerable<TEntity>
The collection of entities.

Remarks

Note that if AutoDetectChangesEnabled is set to true (which is the default), then DetectChanges will be called once before delete any entities and will not be called again. This means that in some situations RemoveRange may perform significantly better than calling Remove multiple times would do. Note that if any entity exists in the context in the Added state, then this method will cause it to be detached from the context. This is because an Added entity is assumed not to exist in the database such that trying to delete it does not make sense.

See Also

Reference

DbSet<TEntity> Class

System.Data.Entity Namespace