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

旧城冷巷雨未停 提交于 2019-12-10 21:26:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!