Alexander Sudarikov
Israel
·
It is very dangerous suggestion, at least when you have more than one running thread. Just think of inserting related records into tables. There has been saved the one record into the first table, and thread context has been switched. Second thread reads data. Oops, there is a problem. EntityFramework, at least version 5, by default uses IsolationLevel = IsolationLevel.Unspecified(it means the isolation level either taken from ambient transaction or, if no transaction exists, will be taken database default isolation level), which means select will be executed in transaction, but we do not now at which isolation level. Here we go, since DbContext use the same connection string , a connection we get is the same connection returned from connection pool, therefore we run into the ambient transaction and see partial data which has not been fixed in database yet.
The problem is not DbContext, the problem is an underlying database connection taken from Connection Pool