Back to directory
In the previous article, we mentioned concurrency conflicts and detailed descriptions. Here, we will talk about it now!
Causes of concurrency conflicts
In fact, the concurrency conflicts in linq to SQL refer to the data {1, zzl, male} retrieved by client A1 during the update operation. This data is also retrieved by client A2 {1, zzl, male}. At this time, A1 re-assigns {1, zzl, female} to the entity and submits the object by submit. The database value is changed to {1, zzl, female}
Concurrent conflicts
During submitchange, A concurrency exception occurs. net will throw System. data. linq. changeConflictException exception. We can capture it and re-submit the data context according to our requirements. In fact, the Code section has been provided in the previous article. Here, write it again.
= (CSet. Inserts. Count> | cSet. Updates. Count >|| cSet. Deletes. Count> &&! (System. Data. Linq. ObjectChangeConflict occ (Exception)
We can see that the ChangeConflicts attribute of the data context is used to obtain the concurrency conflicts of all members. In this case, after all the conflicts are traversed, Resove is performed to resolve the conflicts, finally, the context is submitted to the database to overwrite the original {1, zzl, female}. The last saved content in the database will be the value modified by the A2 client.
Back to directory