1

I have this code that returns a single user:

  return RetryWithExpression<User, User>(u => u.FirstOrDefault(x => x.UserEmail == userEmail));

I am trying to convert it so that It returns many users like this:

return RetryWithExpression<User, List<User>>(u => u.Select(x => x.sUserCity == cityId));

This does not compile and I get an error:

Cannot implicitly convert type 'System.Linq.IQueryable<bool>' to 'System.Collections.Generic.List<User>'. An explicit conversion exists (are you missing a cast?)

How do I return a List from this method?

1 Answer 1

4

I think you want Where which filters. Select does a projection. In your case Select would return an IEnumerable<bool>, hence the compilation error.

return RetryWithExpression<User, List<User>>(u => u.Where(x => x.sUserCity == cityId));

Since RetryWithExpression expects a list, call ToList()

return RetryWithExpression<User, List<User>>(u => u.Where(x => x.sUserCity == cityId).ToList());
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but this dosen't fix the code. I still get an error: Cannot implicitly convert type 'System.Linq.IQueryable<User>' to 'System.Collections.Generic.List<User>'. An explicit conversion exists (are you missing a cast?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.