Is there a reason to use one instance of a DataContext instead of several?

For example, I have 2 methods that use one DataContext (Linq to sql).

 using(DataContext data = new DataContext){
   // doing something
   another_datamethod(data);
 }

 void another_datamethod(DataContext data){
   // doing
 }

Use this style? Or with the same result, I can create a separate “using DataContext”. What benefits will I get if I use one DataContext? Perhaps some cache features?

+3
source share
2 answers

, " ", DataContext - , , . LINQ-to-SQL, "" DataContext. , , ... , , , . , ...

, , . DataContext DataContext. , , , data-dom DataContext. , , . , , -. , - , LINQ-to-SQL , . , , Pro LINQ: # 2008 . -. LINQ-to-SQL , , .

, DataContext ... . , , - .

0

Datacontexts , , - , .

-1

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


All Articles