1

我有这个返回单个用户的代码:

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

我正在尝试对其进行转换,以便它返回许多这样的用户:

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

这不编译,我得到一个错误:

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

如何从此方法返回列表?

4

1 回答 1

4

我想你想要Where哪些过滤器。Select做一个投影。在你的情况下Select会返回一个IEnumerable<bool>,因此编译错误。

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

由于RetryWithExpression需要一个列表,请致电ToList()

return RetryWithExpression<User, List<User>>(u => u.Where(x => x.sUserCity == cityId).ToList());
于 2012-09-02T17:00:38.627 回答