Do I have to close the SQL Connection manually if I use Linq?

前端 未结 3 575
我在风中等你
我在风中等你 2020-12-06 07:15

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 opera

3条回答
  •  囚心锁ツ
    2020-12-06 07:45

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

    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.

提交回复
热议问题