When I instance my "Entities" object in Entity Framework, and make a couple of queries using that Entities object, what happens to connections?
In either case, is it possible to change it so that it does the other thing?
Entity Framework manages a connection pool, which means that EF will reuse connections when possible and only create new ones when it needs to. Whether or not each call creates a new connection depends on many factors. So it's hard to say whether any given set of calls will or will not create new connections.
Because an open connection to the database consumes a valuable resource, the Entity Framework opens and closes the database connection only as needed. You can also explicitly open the connection. For more information, see Managing Connections and Transactions. Once in each application domain.
If the object context opens the connection during an operation, it will always close the connection when the operation is complete. If you manually open the connection, the object context will not close it. Calling Close or Dispose will close the connection.
Basically it opens when a request is called and closes once the results have been disposed or consumed. You can manually open/close or use the same connection using the object context...
This article has a more complete explanation - http://msdn.microsoft.com/en-us/library/bb738582.aspx (archive.org)
Here is the How To on using an entity Connection - http://msdn.microsoft.com/en-us/library/bb738461.aspx (archive.org)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With