DbSet.AddRange(IEnumerable) 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.
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.
public virtual System.Collections.IEnumerable AddRange (System.Collections.IEnumerable entities);
abstract member AddRange : System.Collections.IEnumerable -> System.Collections.IEnumerable
override this.AddRange : System.Collections.IEnumerable -> System.Collections.IEnumerable
Public Overridable Function AddRange (entities As IEnumerable) As IEnumerable
Parameters
- entities
- IEnumerable
The collection of entities to add.
Returns
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.
Applies to
Entity Framework