August 2018
Intermediate to advanced
298 pages
5h 33m
English
Let us try to update the salary of an inserted employee record using Entity Framework:
static void UpdateSalary(){ using (var db = new EmployeeDbContext()) { Employee employee = db.Employees.Where(emp => emp.EmployeeId == 1).FirstOrDefault(); if (employee != null) { employee.Salary = 6500; int recordsUpdated = db.SaveChanges(); Console.WriteLine("Records updated:" +recordsUpdated); Console.ReadLine(); } }}
In the preceding method, we find the employee with EmployeeId = 1. Then, we update the salary of the employee to 6500 and save the employee object to the database. Please note that, in the preceding method, we interact with the database a couple of times—once to find the ...
Read now
Unlock full access