How multiple queries are handled connection wise within the same dbcontext instance

37 Views Asked by At

How does the default implementation of dbcontext in EF core handle the connections for multiple sequential queries within same scope, when the scope is not wrapped within a transaction?

E.G.

  1. Query some data.
  2. Do some math
  3. Query more data
  4. Do more math
  5. return the result

Wrapping the scope in a transaction should force it to use the same connection. Is the same behavior also applied without a transaction?

The best explanation I have found so far is here: "Working with DbContext", heading "Connections". This does not explicitly state, what the exact behaviour is, but from "reading between the lines" I understand that one query = one connection from the pool and after calling the execution method (e.g. ToListAsync, FirstAsync, etc.) the connection is returned to the pool right away.

Is my understanding correct or am I missing something?

0

There are 0 best solutions below