EDIT: given the error
"There is already an open DataReader associated with this Command which must be closed first."
I believe this answer will explain your issue. Your best bet is to let your Reader finish the first command before starting another (you could do this with ToList()
), or collapse the query down to a single call (I believe that you could do this by refactoring your queries into one which uses SelectMany()
).
Keep in mind that turning on MARS may be covering up a bigger problem, and you should understand it fully before you go that route, especially for a web application with the lifetime scope of your DbContext should be setup as the life of a single http request. Doing that is trivial if you're properly manually disposing of your context or if you're using a dependency injection framework.