August 2018
Intermediate to advanced
298 pages
5h 33m
English
Deleting the record is a bit tricky as it involves setting the state directly. In the following method, first we get the object and set the state of the object to Deleted. Using db.Delete method instead of setting a state would imply the record is deleted immediately from the database. However, this is not the case. The actual deletion will be pending until we call SaveChanges. Once we call the SaveChanges method, it will generate the delete query for the object and execute it, which in turn will eventually delete the record in the database:
static void DeleteEmployee(){ using (var db = new EmployeeDbContext()) { Employee employeeToBeDeleted = db.Employees.Where(emp => emp.EmployeeId ...Read now
Unlock full access