Share via


DbSet<TEntity>.AddRange 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.]

Adds the given collection of entities into context underlying the set with each entity being put into the Added state such that it will be inserted into the database when SaveChanges is called.

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

Syntax

'Declaration
Public Overridable Function AddRange ( _
    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.AddRange(entities)
public virtual IEnumerable<TEntity> AddRange(
    IEnumerable<TEntity> entities
)
public:
virtual IEnumerable<TEntity>^ AddRange(
    IEnumerable<TEntity>^ entities
)
abstract AddRange : 
        entities:IEnumerable<'TEntity> -> IEnumerable<'TEntity> 
override AddRange : 
        entities:IEnumerable<'TEntity> -> IEnumerable<'TEntity> 
public function AddRange(
    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 adding any entities and will not be called again. This means that in some situations AddRange may perform significantly better than calling Add multiple times would do. Note that entities that are already in the context in some other state will have their state set to Added. AddRange is a no-op for entities that are already in the context in the Added state.

See Also

Reference

DbSet<TEntity> Class

System.Data.Entity Namespace