I have one DbContext (Entity Framework 6.0) and 1,000 objects.
For each object, I start to save its into database or update its data with a separate thread/task using the same DbContext.
This is what I got:
- For thread: EntityCommandExecutionException - There is already an open DataReader associated with this Command which must be closed first. This exception occurred right after the second thead is started.
- For task: everything is fine. All object is added/updated.
I understand that because of using the same DbContext object and multiple calls to it, so I got the exception with thread. But I'm not sure.
Question: Why do I get the differences as well as exception with thread here?
I don't understand much about the task and TPL library. I have used Thread for several small scale projects before.