var result = _context.Employees
.Where(x => !x.IsDeleted)
.Where(x => x.ClientId > (clientId > 0 ? clientId - 1 : -1))
.Where(x => x.ClientId < (clientId > 0 ? clientId + 1 : 1000))
.Where(x => x.ContractorFlag == employeeFlag);
return result;
If clientId = 0 we want ALL employees,. but for any clientId between 1 and 999 we want only clients with that ID. I was having issues with seperate LINQ statements not being the same (Deleted/Clients filters need to be on all queries), so by add these two lines it works (all be it until we have 999+ clients - which would be a happy re-factor day!!