示例#1
0
 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;
     }
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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);
     }
 }