public void EditCustomer(Customers customer) { var cust = _customerDBContext.Customers.AsNoTracking().Where(q => q.CustomerId == customer.CustomerId); foreach (var cus in cust) { if ((customer.CustomerId == cus.CustomerId)) { _customerDBContext.Customers.Remove(cus); } } _customerDBContext.Attach(customer); IEnumerable <EntityEntry> noChangeEntities = _customerDBContext.ChangeTracker.Entries().Where(x => x.State == EntityState.Unchanged); foreach (EntityEntry cusEE in noChangeEntities) { cusEE.State = EntityState.Modified; } _customerDBContext.Entry(customer).State = EntityState.Modified; _customerDBContext.SaveChanges(); }