SubmitChanges();
262
Chapter 13: More about Entity Classes
textBox1.Text = "Contacts removed successfully";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Like the update example, this code utilizes a standard LINQ query that is populating the entity class
with all contacts whose last name is ??????Klein??™??™ (essentialy all the names used in the Insert example above).
As with the update example, each contact returned in the query is then iterated over, calling the Remove
method on the object entity and then calling the SubmitChanges method of the DataContext class.
As you can see, manipulating data is easy, yet effective. LINQ to SQL offers a lot of flexibility for manipulating,
and maintaining, data, and changes to data.
Concurrent Changes and Concurrency
Conflicts
In LINQ to SQL, the DataContext has built-in support for optimistic concurrency. In optimistic concurrency
mode, updates succeed only if the state of the database has not changed since you first retrieved
the data. Conflicts to this state can occur in the LINQ to SQL object when both of the following are true:
??‘ The application tries to write changes back to the database.
Pages:
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423