//Changed the state of the account. public void ChangeState() { //The DB instance BankOfBIT_ArshdeepSanghaContext db = new BankOfBIT_ArshdeepSanghaContext(); //The old id of the account state AccountState oldId = db.AccountStates.Where(x => x.AccountStateId == this.AccountStateId).SingleOrDefault(); //The new id of the account state which is null. AccountState newId = null; //Runs the loop until they don't match while (newId != oldId) { //when the ids are equal oldId = newId; //The new id fetches the id of the account state. newId = db.AccountStates.Where(x => x.AccountStateId == this.AccountStateId).SingleOrDefault(); //The new id is assigned the right state newId.StateChangeCheck(this); } }