问题
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:
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.
来源:https://stackoverflow.com/questions/27974524/how-to-use-bulk-insert-in-entity-framework-using-object-context