Entity Framework Core in Action by Jon Smith
Author:Jon Smith [Smith, Jon]
Language: eng
Format: epub, pdf
Tags: computers, Database Administration & Management, Programming, Object Oriented, Languages, .Net, Software Development & Engineering, General, internet, Web Programming, Web Services & APIs
ISBN: 9781617294563
Google: x519swEACAAJ
Publisher: Manning
Published: 2018-08-04T23:39:48.945520+00:00
Figure 8.7 After the user has changed the salary and clicked the Change button, the new salary and the original salary values are sent back to the web application. It then calls the UpdateSalary method, shown in listing 8.16, that both updates the salary and sets the original value expected in the database when it does the update. If a concurrency conflict is found, a new screen with an appropriate error message is shown to the user, who can then accept the existing database state, or apply their own update to the employee.
Listing 8.21 shows the entity class used for this example, with the Salary property set as a concurrency token. You also create a method called UpdateSalary that contains the code you need to execute in order to update the Salary property in such a way that DbUpdateConcurrencyException will be thrown if the Salary value has changed from the value originally shown on the userâs screen.
Listing 8.21 Entity class used to hold an employeeâs salary with concurrency check
public class Employee { public int EmployeeId { get; set; } public string Name { get; set; } [ConcurrencyCheck] public int Salary { get; set; } â public void UpdateSalary â¡ (DbContext context, int orgSalary, int newSalary) { Salary = newSalary; ⢠context.Entry(this).Property(p => p.Salary) ⣠.OriginalValue = orgSalary; ⣠} }
â Salary property set as a concurrency token by the ConcurrencyCheck attribute.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7737)
Robo-Advisor with Python by Aki Ranin(7635)
Offensive Shellcode from Scratch by Rishalin Pillay(6110)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(5033)
Ego Is the Enemy by Ryan Holiday(4959)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4438)
Python for ArcGIS Pro by Silas Toms Bill Parker(4187)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3894)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3633)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3285)
Speed Up Your Python with Rust by Maxwell Flitton(3232)
Liar's Poker by Michael Lewis(3227)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3195)
Extreme DAX by Michiel Rozema & Henk Vlootman(3172)
Agile Security Operations by Hinne Hettema(3124)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3110)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3083)
Cryptography Algorithms by Massimo Bertaccini(3002)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2984)
