Entity Framework Core: A second operation started on this context before a previous operation completed

Working with EF Core across multiple controller services I was receiving the following Entity Framework Core: A second operation started on this context before a previous operation completed. The link for StackOverflow talks about ensuring your dbContext is correctly injected into the ServiceCollection which mine was. A bit of headscratching I was thinking that my foreach loop look fine there was nothing too crazy/costly happening. Then I realised the objects I was looping over hadn’t terminated with a ToList() or similar. Once I added the ToList() the context returned the scope and happy days!

Leave a Reply