When do Entity Framework Database Connections open and close?

.net-3.5 connection entity-framework

Question

What happens to connections when I instance my "Entities" object in Entity Framework and run a few queries utilizing that Entities object?

  • When I instance the object, does it create a connection, and does it close it when I dispose of it?
  • Or does it create and shut down connections for each each query I run?

Is there a way to modify it in either situation such that it does the opposite action?

1
33
9/4/2015 8:34:19 PM

Accepted Answer

In essence, it starts when a request is made and ends when the results have been discarded or used. You may utilize the same connection by manually opening and closing it or by utilizing the object context.

A more thorough explanation may be found in this article: http://msdn.microsoft.com/en-us/library/bb738582.aspx

The How To for utilizing an Entity Connection is shown here. the 16-zzz-zzz

28
8/15/2009 7:49:34 PM

Popular Answer

In EF6, the behavior changed a little bit to let you pass in open connections or open the EF connection later yourself. Observe https://msdn.microsoft.com/en-us/library/dn456849(v=vs.113).aspx



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow