Entity Framework Insert stored procedure in a loop

你。 提交于 2020-01-15 07:50:21

问题


Trying to execute an insert stored procedure in a loop using Entity Framework, something like this:

var context = new Entities()
var items = context.GetAllItems().ToList();

foreach(var item in items) 
{
    // Other select and update procedures
    context.InsertProcedure(item.Prop1);
}

context.SaveChanges();

but I am getting an exception.

New transaction is not allowed because there are other threads running in the session

Anybody had this before?


回答1:


It turned out there is another exception, but looks like this exception is always thrown when there is a problem within the loop.

What I did is that I changed the return type of the stored procedure to None in Model Browser



来源:https://stackoverflow.com/questions/40984421/entity-framework-insert-stored-procedure-in-a-loop

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