public void ConcurrencyTests() { //Get the same record but loaded from two separate contexts so the tracking won't overlap. ICustomerRepository repository = new CustomerRepository(_dbContext); var secondContext = new EntityContext(); //add new customer to db. var newCustomer = CreateCustomer(repository); //load this customer from context 1 var firstCustomer1 = repository.GetById(newCustomer.CustomerId); firstCustomer1.City = "newCity3"; //load the same customer from context 2 ICustomerRepository secondRepository = new CustomerRepository(secondContext); var firstCustomer2 = secondRepository.GetById(firstCustomer1.CustomerId); //Check the states Debug.WriteLine(_dbContext.Entry(newCustomer).State); Debug.WriteLine(_dbContext.Entry(firstCustomer1).State); Debug.WriteLine(secondContext.Entry(firstCustomer2).State); //Modify the second customer. We have the same TimeStamp as the original record //however the timestamp in the database would've been updated already. firstCustomer2.Address = "222 main st" + DateTime.Now.ToString(); Debug.WriteLine(secondContext.Entry(firstCustomer2).State); //This should update that customer. repository.Update(firstCustomer1); repository.Save(); //This should throw an exception. secondRepository.Update(firstCustomer2); secondRepository.Save(); secondContext.Dispose(); }