In the case of LINQ-to-SQL ~ Concurrency conflicts and responses in LINQ-to-SQL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.