Entity Framework 何时打开和关闭数据库连接? [英] When does Entity Framework open and close Database Connections?

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

问题描述

当我在 Entity Framework 中实例化我的实体"对象并使用该实体对象进行几个查询时,连接会发生什么情况?

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?

推荐答案

基本上它在调用请求时打开,并在结果被释放或使用后关闭.您可以使用对象上下文手动打开/关闭或使用相同的连接...

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

这篇文章有更完整的解释——http://msdn.microsoft.com/en-us/library/bb738582.aspx (archive.org)

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

这是使用实体连接的方法 -http://msdn.microsoft.com/en-us/library/bb738461.aspx (archive.org)

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

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

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