Calling 'Read' when the data reader is closed is not a valid operation - cSharp Coder

Latest

cSharp Coder

Sharp Future

Thursday, September 3, 2020

Calling 'Read' when the data reader is closed is not a valid operation

 The entity framework uses lazy evaluation. This means that the query is not actually executed against the database when you create it, it is executed when you actually need the data out. Consequently, the data context must still be open when you process the query.

Converting the query to an IList will force the query to be executed. If the data context is closed at this point you will get an error like this.

I can't explain why you didn't get this before if you haven't changed any code, but this is what I would be looking at.

Perhaps post your code, this might help diagnose the problem.

No comments:

Post a Comment