Open;
LINQ to SQL
[ 122 ]
The Deserts DataContext can use the connection object for the queries and updates
to the database. After performing the task, the connection should be closed by the
DataContext object.
Deserts db = new Deserts(connection);
var icecreams = from cat in db.Items
where cat.CategoryID == 1
select cat;
db.Connection.Close();
The different ways of handling transactions, are stated as follows:
1. Explicit Local Transaction: When SubmitChanges method is called, and if
the transaction property is set, then the SubmitChanges method is executed
in the same transaction context.
2. Explicit Distributed Transaction: LINQ to SQL queries can also be called
within the scope of the transaction. The SubmitChanages method can be
called for submitting the execution of the queries.
3. Implicit Transaction: When the SubmitChanges method is called, LINQ
to SQL checks to see if the call is within the scope of a transaction or if the
transaction property is set. If it is present, it executes within the transaction,
otherwise it starts a local transaction and executes the commands.
Pages:
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203