Vasilescu Andrei Vasilescu Andrei - 11 months ago 52
C# Question

Can multiple controllers access the same database at the same time using different dbcontexts?

I am using entity framework and a controller with async methods.

While one controller is playing with the database via an async method , the server might receive a request from another client to play with the same database.

I understand that dbcontext is not thread safe.

Why is there not a problem here?

Answer Source

I understand that dbcontext is not thread safe.

That means that the same DbContext instance should not be used from multiple threads. It's perfectly fine for multiple DbContexts to hit a database on different threads.

Now what happens in the database in that situation depends on the databases's locking/concurrency settings, but that's another question.