How to use Bulk Insert in Entity Framework using Object Context?

asp.net-mvc c# entity-framework entity-framework-6 linq-to-entities

Question

I would like to use Object Context instead of DbContext to call Bulk Insert in Entity Framework 6. How can I do that?

I would like to do something like

readonly ObjectContext obContext:

public void BulkInsert<T>(IEnumerable<T> items) where T : class, new()
{
    obContext.BulkInsert(items);
}

But I am not able to do this.

1
3
1/15/2015 10:59:05 PM

Popular Answer

With entity framework 6, you can use this nice nuget package to bulk insert, and you can use it with the DbContext object.

so something like this:

using (var db = new YourDbContext())
{
   EFBatchOperation.For(db, db.BlogPosts).InsertAll(list);
}

https://github.com/MikaelEliasson/EntityFramework.Utilities

Hope this helps.

1
1/16/2015 2:15:48 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