I noticed this exception being thrown in some code someone else wrote and am trying to fix it. We are using ASP.NET MVC with Entity Framework 6.0. I've looked elsewhere but not finding anything that's relevant because the exception in my case is being created by a race condition (rather than an object which isn't cleaned up).
Background:
- A js function is iterating through an array and making an ajax call to a controller for each item.
The controller calls a service, and ultimately the repository which is using entity framework + linq, which looks something like this:
public IList<int> GetData(IList<int> ids) { var query = from widget in _context.Widgets .Where(x => x.SourceId == 1 && ids.Contains(x.ID)) from widgetSourceType in widget.WidgetSource .Where(x => x.WidgetSourceType.Name == "foo") select widget.ID; return query.ToList(); }
It's bombing out on the query.ToList() line, which I believe is when the query is actually executed. It looks pretty clear to me that the ajax calls are firing multiple operations concurrently, and the second is trying to access the same connection before the first is done with it. But I'm not sure on how to fix. Has anyone had experience with this?