I am tring to update the field PageContentPhoto of my Table PageContent using this code:
var applicationDbContext = _context.PageContent.Include(p => p.ParentMenuPage).Include(p => p.ParentPageSection);
var chooseMyscript = "script1";
if (chooseMyscript == "script1")
{
foreach (var item in applicationDbContext)
{
var fetched = _context.PageContent.Find(item.PageContentId);
fetched.PageContentPhoto = "Submenu" + "-" + item.PageContentId + "-" + item.MenuSubId + "-" + item.PageSectionId;
if (item.PageSectionId == 2)
{
fetched.PageContentVisible = false;
}
_context.Entry(fetched).State = EntityState.Modified;
_context.SaveChanges();
}
}
return View(await applicationDbContext.ToListAsync());
When i run it I get this error:
An unhandled exception occurred while processing the request. SqlException: New transaction is not allowed because there are other threads running in the session. Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action wrapCloseInAction)
What is wrong?