问题
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