The DataContext class has a Refresh method that refreshes the object state with the
original data in the database. The enumeration tells Refresh what to do in case of a conflict.
RefreshMode has three values:
??‘ KeepChanges??”Tells Refresh to keep the current changed values in the object but updates the
other values with the data from the database.
??‘ KeepCurrentValues??”Tells Refresh to replace the current object values with values from the
database.
??‘ OverwriteCurrentValues??”Tells Refresh to override all of the current object values with the
values from the database.
An example from earlier in the chapter illustrates the use of RefreshMode as well as the ConflictMode
enumeration and ChangeConflictException class. The highlighted lines point out the pertinent code.
265
Part III: LINQ to SQL
try
{
var conQuery =
from con in db.Contacts
where con.FirstName == "Scott"
select con;
// there are 15 Scott??™s in the table, so 15 changes should be made
foreach (Contact cont in conQuery)
{
cont.MiddleName = "L";
cont.NameStyle = 1;
}
db.
Pages:
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428