Do I have to close the SQL Connection manually if I use Linq?(如果我使用 Linq,是否必须手动关闭 SQL 连接?)
问题描述
传统上,当我们使用SQL字符串做一些工作时,我们必须在关闭页面之前关闭sql连接,我想知道如果我使用Linq进行数据操作是否还需要手动关闭连接?
Traditionally, when we use SQL string to done some work, we have to close the sql connection before the page being closed, I was wondering if I use Linq to do the data operations do I still need to close the connection manually?
推荐答案
这与 这个问题.
LINQ to SQL 将在需要时打开和关闭连接 - 您实际上不必处理 DataContext.但是,有时您可以欺骗"上下文以在您不应该打开连接时保持打开状态 - 我个人喜欢将其作为理所当然的处理.有关 LINQ to SQL 团队的 Matt Warren 的更多详细信息,请参阅我对另一个问题的回答.
LINQ to SQL will open and close connections when it needs to - you don't really have to dispose of the DataContext. However, there are times when you can "trick" the context into leaving a connection open when you shouldn't - I personally like to dispose of it as a matter of course. See my answer to the other question for a bit more detail from Matt Warren of the LINQ to SQL team.
不过,我不了解实体框架.
I don't know about the Entity Framework, however.
这篇关于如果我使用 Linq,是否必须手动关闭 SQL 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果我使用 Linq,是否必须手动关闭 SQL 连接?
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
