In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you Linq open concurrency control example analysis, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
First let everyone know about Linq open concurrency control, and then introduce Linq open concurrency comprehensively.
Linq Open concurrency control
In the LINQ to SQL object model, a Linq open concurrency conflict occurs when both of the following conditions are met: the client attempts to commit changes to the database; and one or more update check values in the database have been updated since the client last read them. Resolution of this conflict involves identifying which members of the object conflict, and then deciding how you want to handle it.
Linq Optimistic Concurrency
Note: In this example, before you read the data, another user has modified and submitted an update to the data, so there is no conflict.
//we open a new connection to impersonate another user NorthwindDataContext otherUser_db = new NorthwindDataContext(); var otherUser_product = otherUser_db.Products.First (p => p.ProductID == 1); otherUser_product.UnitPrice = 999.99M; otherUser_db.SubmitChanges(); //Our current connection var product = db.Products.First (p => p.ProductID == 1); product.UnitPrice = 777.77M; try { db.SubmitChanges();//current connection executed successfully} catch (ChangeConflictException) { }
Explanation: After we read the data, another user obtains and submits an update to the data. At this time, when we update the data, we cause a concurrency conflict. Rollback occurs, allowing you to retrieve newly updated data from the database and decide how to proceed with your own updates.
//current user var product = db.Products.First(p => p.ProductID == 1); //we open a new connection to impersonate another user NorthwindDataContext otherUser_db = new NorthwindDataContext() ; var otherUser_product = otherUser_db.Products.First(p => p.ProductID == 1); otherUser_product.UnitPrice = 999.99M; otherUser_db.SubmitChanges(); //The current user modifies product.UnitPrice = 777.77M; try { db.SubmitChanges(); } catch (ChangeConflictException) { //Exception! } The above is all the content of this article,"Linq open concurrency control example analysis", thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.