Suppose I have code in this form:
using (var dc = new MyDataContext()) { // ...code that may or may not look up objects via Linq-to-SQL... // ...code that may or may not *update* objects via Linq-to-SQL... // and call SubmitChanges... // Non-Linq-to-SQL code: dc.Connection.Open(); // <== I believe I need to do this using (SqlCommand cmd = dc.Connection.CreateCommand()) { // ...set up the command... using (SqlDataReader reader = cmd.ExecuteReader()) { // ...use the reader here... } } // ...more code that may or may not look up objects via Linq-to-SQL... // ...more code that may or may not *update* objects via Linq-to-SQL... // and call SubmitChanges... }
Is it safe, for example, am I allowed to co-opt the connection this way? Should I call correctly Openif the code above was not supposed to make any DB calls?
Open
This MSDN page seems to say that this is normal:
DataContext is the main channel through which you connect to the database, extract objects from it and send the changes back. You use the DataContext the same way you used the ADO.NET SqlConnection.
(, DataContext. , .)
DataContext
, .Net 3.5 .
, . , , , LINQ-to-SQL . , - , .
LINQ-SQL , using TransactionScope.
using TransactionScope
Entity Framework, . , , LINQ-to-SQL - /, .
Source: https://habr.com/ru/post/1598506/More articles:Name ambiguity - c ++Streaming Video / Audio from an iOS Device - iosHow can I create a new activity where I will have the opportunity to add new items from the database? - javaHow to implement digital frame in ios app? - iosHow to check if a string contains a substring with a pattern? like abc * xyz - c #Do I need to create / compile SSRS reports? - reporting-servicesTaskStackBuilder in PendingIntent not working - androidThe Rails / JS-G + button only works after reloading the page in some cases - javascript.net webclient returns 500 errors, but browser url is fine - httpHybrid vs Native Development (Android and iOS) - nativeAll Articles