public void DeleteCustomersByAddress(string address) { using (RETAILContext context = new RETAILContext()) { List<Customer> entities = context.Customers.AsQueryable().Where(c => c.Address == address).ToList(); foreach (var entity in entities) { context.Set<Customer>().Remove(entity); } context.SaveChanges(); } }
public void DeleteAllCustomers() { using (RETAILContext context = new RETAILContext()) { List<Customer> entities = context.Customers.AsQueryable().ToList(); foreach (var entity in entities) { context.Set<Customer>().Remove(entity); } context.SaveChanges(); //context.ExecuteStoreCommand("TRUNCATE TABLE [RETAIL].[STORE].[Customer]"); } }
public void InsertCustomer(DomainModels.Customer customer) { using (RETAILContext context = new RETAILContext()) { Customer entity = Mapper.Map<DomainModels.Customer, Customer>(customer); context.Customers.Add(entity); context.SaveChanges(); customer.Id = entity.Id; } }
public void UpdateCustomer(DomainModels.Customer customer) { using (RETAILContext context = new RETAILContext()) { Customer entity = context.Customers.AsQueryable().Single(c => c.Id == customer.Id); entity.Name = customer.Name; entity.Address = customer.Address; entity.Phone = customer.Phone; context.SaveChanges(); } }