Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity fails on simulataneous AJAX posts
    text
    copied!<p>I have an action that updates the database based on a Jquery Droppable/Sortable. The first AJAX post works fine, but the second one gives me the error:</p> <pre><code> New transaction is not allowed because there are other threads running in the session. </code></pre> <p>It's being posted to 2 separate actions on the same controller, using the same UnitOfWork in the controller. Not sure what I have to do to fix this.</p> <p>EDIT: these are the two service methods being called:</p> <pre><code>public void NavItemSort(List&lt;string&gt; orderArray, string navID, string subNavID) { var newOrderArray = orderArray.Where(s =&gt; !string.IsNullOrWhiteSpace(s)).ToList(); var orderArrayIDs = newOrderArray.Select(x =&gt; x.Replace("ContentItem", "")).ToList(); var itemToBeSorted = Convert.ToInt32(orderArrayIDs.FirstOrDefault()); var itemContext = cmsUnitOfWork.NavigationItems.Find().Where(x =&gt; x.ID == itemToBeSorted).ToList().FirstOrDefault(); var currentSortOrder = cmsUnitOfWork.NavigationItems.Find() .Where(x =&gt; x.NavID == itemContext.NavID &amp;&amp; (itemContext.ParentID == null) ? x.ParentID == null : x.ParentID == itemContext.ParentID).ToList(); var existingItems = currentSortOrder.Select(x =&gt; x.ID).ToList(); List&lt;string&gt; existingItemsString = existingItems.ConvertAll&lt;string&gt;(x =&gt; x.ToString()).ToList(); var newNavItemID = existingItemsString.Except(orderArray).FirstOrDefault(); var currentSortOrderExcept = currentSortOrder.Where(x =&gt; x.ID != Convert.ToInt32(newNavItemID)); foreach (var x in currentSortOrderExcept) { int sortOrderInt = orderArrayIDs.IndexOf(orderArrayIDs.Where(z =&gt; int.Parse(z) == x.ID).ToList().FirstOrDefault()) + 1; NavigationItem navigationItem = new NavigationItem() { HasChild = x.HasChild, Level = x.Level, NavID = x.NavID, ID = x.ID, ParentID = x.ParentID, PageID = x.PageID, URL = x.URL, Title = x.Title, SortOrder = sortOrderInt, }; if (navigationItem.SortOrder != null &amp;&amp; navigationItem.SortOrder != 0) { cmsUnitOfWork.NavigationItems.Update(x, navigationItem); } } cmsUnitOfWork.Commit(); } public void NavItemAdd(List&lt;string&gt; orderArray, string NavID, string subNavID){ var newOrderArray = orderArray.Where(s =&gt; !string.IsNullOrWhiteSpace(s)).ToList(); var orderArrayIDs = newOrderArray.Select(x =&gt; x.Replace("ContentItem", "")).ToList(); NavID = NavID.Replace("nav", ""); int NavIDInt = int.Parse(NavID); int subNavIDInt = int.Parse(subNavID); var existingNavItems = cmsUnitOfWork.NavigationItems.Find().Where(x =&gt; x.NavID == NavIDInt &amp;&amp; x.ParentID == subNavIDInt).ToList(); int currentSortOrder = 0; if (existingNavItems.Count() != 0) { currentSortOrder = existingNavItems.Max(x =&gt; x.SortOrder); } var existingItems = existingNavItems.Select(x =&gt; x.ID).ToList(); List&lt;string&gt; existingItemsString = existingItems.ConvertAll&lt;string&gt;(x =&gt; x.ToString()).ToList(); var newNavItemID = orderArray.Except(existingItemsString).FirstOrDefault(); int newNavIDInt = int.Parse(newNavItemID); var newNavItemList = cmsUnitOfWork.NavigationItems.Find().Where(x =&gt; x.ID == newNavIDInt).ToList(); var newNavItem = newNavItemList.FirstOrDefault(); var parentNav = cmsUnitOfWork.NavigationItems.Find().Where(x =&gt; x.ID == subNavIDInt).ToList().FirstOrDefault(); NavigationItem navigationItemUpdated = new NavigationItem() { ID = newNavItem.ID, Level = 2, NavID = NavIDInt, PageID = newNavItem.PageID, Title = newNavItem.Title, URL = newNavItem.URL, ParentID = subNavIDInt, SortOrder = currentSortOrder + 1 }; cmsUnitOfWork.NavigationItems.Update(newNavItem, navigationItemUpdated); cmsUnitOfWork.Commit(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload