How to create a DbSet with a list of entities

.net entity-framework

Question

DbSet.Add() adds a single Entity to DbSet. But there is no DbSet.AddRange() to add a list of entities. Is there a method I can call directly from EF that allows me to add a list of Entities? If not, is there any reason why EF does not provide such a method?

1
8
2/12/2012 1:49:32 AM

Popular Answer

In EF6 both DbSet.AddRange and DbSet.RemoveRange are available.

The reason to implement them is to improve the performance, what is done by disabling DetectChanges for each individual addition or removal of an entity.

More details:

NOTE: There isn't still official documentation for this method, as EF is still RC1.

UPDATE: EF6 has been release, and the official documentation for .AddRange() is here, but the explanation of what's happening inside it's in the links above.

11
3/13/2014 11:22:54 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow