Is DbContext thread safe?

jcvandan picture jcvandan · May 25, 2011 · Viewed 40.4k times · Source

I was wondering if the DbContext class is thread safe, I am assuming it's not, as I am currently executing paralell threads that access the DbContext in my application and I am getting a host of locking exceptions and other things that look like they may be thread related.

Until recently I wasn't getting any errors...but until recently I wasn't accessing the DbContext in the threads.

If I am right, what would people suggest as a solution?

Answer

DanielB picture DanielB · May 25, 2011

It's not thread safe. Simply create a new instance of DbContext in you thread.