什么时候实体框架的打开和关闭数据库连接? [英] When does Entity Framework open and close Database Connections?

查看:184
本文介绍了什么时候实体框架的打开和关闭数据库连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我实例在实体框架我的实体的对象,使一对夫妇使用实体对象的查询,恰好连接了什么?

When I instance my "Entities" object in Entity Framework, and make a couple of queries using that Entities object, what happens to connections?

  • 是否打开连接时,我实例的对象,并关闭它,当我处理它?<​​/ li>
  • 或者它打开和关闭每一个单独的查询方面,我执行?
  • Does it open a connection when I instance the object, and close it when I dispose of it?
  • Or does it open and close a connection for each single query I execute?

在这两种情况下,是有可能改变它,这样它的另一件事?

In either case, is it possible to change it so that it does the other thing?

推荐答案

基本上它打开时,一个请求被调用和关闭,一旦结果已被处置或被消耗。您可以使用对象范围内手动开启/关闭或使用相同的连接...

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...

这篇文章有一个更完整的解释 - <一href="http://msdn.microsoft.com/en-us/library/bb738582.aspx">http://msdn.microsoft.com/en-us/library/bb738582.aspx

This article has a more complete explanation - http://msdn.microsoft.com/en-us/library/bb738582.aspx

下面是如何使用的实体连接 - 在<一个href="http://msdn.microsoft.com/en-us/library/bb738461.aspx">http://msdn.microsoft.com/en-us/library/bb738461.aspx

Here is the How To on using an entity Connection- the http://msdn.microsoft.com/en-us/library/bb738461.aspx

这篇关于什么时候实体框架的打开和关闭数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆