Should the LINQ context be closed each time?

In LINQ to SQL, do you need to close the context after making a selection in the database (and, of course, after using the data)? if I leave it open, does this mean that the connection to the server remains open?

Thanks Lucian

+3
source share
4 answers

A suitable connection is not closed or placed until you close the DataContext using the Dispose method. You should always call Dispose after using the DataContext. Think of the DataContext as a traditional Connection object, which is more or less what is under the hood.

+2
source

Q. ?

. , . , ToList (TSource) . , , DataReader, LINQ to SQL.

:

, DataContext .

(, (MARS). . (MARS).


from MSDN LINQ to SQL

+2

LiNQ. , , .

ASP.NET, , , - asp.net. open, , , Linq.

Windows Forms ( ), .

+1

: , datacontext , , . , .

, . , .

+1

Source: https://habr.com/ru/post/1703239/


All Articles