The code is as follows: |
Copy code |
Public abstract class dbBase { Public virtual void SubmitChanges () { ChangeSet cSet = db. GetChangeSet (); If (cSet. Inserts. Count> 0 | CSet. Updates. Count> 0 | CSet. Deletes. Count> 0) { Try { Db. SubmitChanges (System. Data. Linq. ConflictMode. ContinueOnConflict ); // Db. SubmitChanges (); } Catch (System. Data. Linq. ChangeConflictException ex) { Foreach (System. Data. Linq. ObjectChangeConflict occ in db. ChangeConflicts) { // Use the value in the current database to overwrite the value of the entity object in the Linq cache Occ. Resolve (System. Data. Linq. RefreshMode. OverwriteCurrentValues ); // Use the value of the entity object in the cache of Linq to overwrite the value in the current database. Occ. Resolve (System. Data. Linq. RefreshMode. KeepCurrentValues ); // Only update the value of the changed field in the object. Other values remain unchanged. Occ. Resolve (System. Data. Linq. RefreshMode. KeepChanges ); } Db. SubmitChanges (); } } } } |
All data operation Objects inherit from it and use its SubmitChanges method.