Example #1
0
        public static Customer Update(Customer c)
        {
            BookRegContext context = new BookRegContext();

            context.Entry(c).State = EntityState.Modified;

            context.SaveChanges();

            return(c);
        }
Example #2
0
        public static void DeleteCustomer(Customer c)
        {
            var context = new BookRegContext();

            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //Alternative
            context.Entry(c).State =
                System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
        public static void DeleteCustomer(Customer c)
        {
            BookRegContext context = new BookRegContext();

            //Telling Entity Framework (EF) that the customer
            //exists, and we want it removed from the DB
            //context.Customer.Attach(c);
            //context.Customer.Remove(c);

            //ALTERNATIVE
            context.Entry(c).State = EntityState.Deleted;

            context.SaveChanges();
        }