public static void DeleteCustomer(Customer c) { using (var context = new BookRegistrationEntities()) { context.Customer.Add(c); // "Track" with EF context.Entry(c).State = EntityState.Deleted; // Tell EF we are removing it int rowsAffected = context.SaveChanges(); // Update on database // int rowsAffected is optional } }
public static Customer UpdateCustomer(Customer c) { using (var context = new BookRegistrationEntities()) { context.Customer.Add(c); // Add to context // Tell EF we are updating an existing entity context.Entry(c).State = EntityState.Modified; // Tell EF it has been modified context.SaveChanges(); return(c); } }