We are talking for one ObjectContext per Request concept. (Web Application) WE dont close connection between Application_BeginRequest and Application_EndRequest. We have a single ObjectContext during the Request. We open it and dont close during the Request.
There is a ExecuteStoreCommand in Entity Fra开发者_如何学运维mework but this is a little dangerous for performance. Because when we use it (I think) it closes a connection. And when we use ObjectContext after it connection is opened again (this is performance problem?)
So is there any alternative to ExecuteStoreCommand or am I crazy :)
"Closing" and "Opening" connection doesn't have any real performance impact if you correctly use connection pooling. The connection pool holds several opened connections which are reused by multiple subsequent actions. Open in most cases only means "get me a connection from the pool" and close means "return the connection to the pool". The connection pool will handle opening a new connection if none is available in the pool as well as limit number of concurrently used connections. Connection pool is defined per connection string + user identity.
ExceuteStoreCommand
closes connection only if no connection was opened when the command started execution. It means that if you use your own connection passed to the context it will not close it.
精彩评论