我有以下工作查询:
posts.Where(post => post.Fields .Where(x => x.RegionId == "RecipeArticleDetails" && (x.FieldId == "RecipePrepTime" || x.FieldId == "RecipeCookTime") ) .GroupBy(x => x.PostId) .Select(x => new { ID = x.Key, Value = x.Sum(y => Convert.ToInt32(y.Value)) }) .Where(x => x.Value > 10 && x.Value < 40) .Any() ) List<string> suppliedTimes = new List<string>(){ "10-60","0-10" };
我想替换Where(x => x.Value > 10 && x.Value < 40)
,以便从范围列表中查找:
List<string> suppliedTimes = new List<string>(){ "10-60","0-10" };
我的理解是,我可以使用select来迭代项目:
posts.Where(post => suppliedTimes.Select(x => new {low = Convert.ToInt32(x.Split("-",StringSplitOptions.RemoveEmptyEntries)[0]), high = Convert.ToInt32(x.Split("-",StringSplitOptions.RemoveEmptyEntries)[1]) }) .Any( a => post.Fields .Where(x => x.RegionId == "RecipeArticleDetails" && (x.FieldId == "RecipePrepTime" || x.FieldId == "RecipeCookTime") ) .GroupBy(x => x.PostId) .Select(x => new { ID = x.Key, Value = x.Sum(y => Convert.ToInt32(y.Value)) }) .Where(x => x.Value > a.low && x.Value < a.high) .Any() ) )
然而,此代码导致错误:could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
请有人解释一下我是如何做到这一点的,以及为什么我所拥有的不起作用。