public static void DeleteCustomer(Customer c) { using (var context = new BookRegistrationEntities()) { context.Customer.Add(c); context.Entry(c).State = EntityState.Deleted; int rowsAffecteed = context.SaveChanges(); } }
public static Customer UpdateCustomer(Customer c) { using (var context = new BookRegistrationEntities()) { context.Customer.Add(c); context.Entry(c).State = EntityState.Modified; context.SaveChanges(); return c; } }
public static Customer UpdateCustomer(Customer c) { using (var context = new BookRegistrationEntities()) { context.Customer.Add(c); // Tell EF we are updating an existing entity context.Entry(c).State = EntityState.Modified; context.SaveChanges(); return(c); } }
public static Customer UpdateCustomer(Customer c) { // If a customer ID = 0 EF will know this is a new customer. using (var context = new BookRegistrationEntities()) { //Adds to context, not DB(technically) so it starts tracking it context.Customer.Add(c); //Tell EF we are updating an existing entity context.Entry(c).State = EntityState.Modified; context.SaveChanges(); return(c); } }