本文介绍了如果使用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?

推荐答案

这与.

This is very similar to (but not quite a duplicate of) this question.

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连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多