我对截图中的黄色部分有意见。我想知道SelectedGroup是否为空。除了添加到该表达式的术语之外,还需要添加另一个条件。就这样。
c => SelectedGroup.Contains (c.CourseGroup.Id) 选择ID在该范围内的所有SelectedGroups。我写的这个查询不起作用。给出的错误是它不能被转换成SQL查询。我没有办法解决这个问题。请帮帮我
有关我的代码的更多详细信息-这是我的代码库:
发布于 2019-05-04 01:19:52
坐上combine的车,它帮不了你。如果你真的想返回一个queryable,你就不应该编译你的表达式。
你可以做的是:
Expression<Func<Course, bool>> expression = c => (string.IsNullOrEmpty(Title) || EF.Functions.Like(c.CourseTitle, $"%{Title}%")
&& c.IsDeleted == IsDeleted);
switch (statusType)
{
case PriceStatusType.All:
break;
case PriceStatusType.Free:
queryable = queryable.Where(expression).Where(c => c.CoursePrice < 1000);
break;
case PriceStatusType.Cash:
queryable = queryable.Where(expression).Where(c => c.CoursePrice <= MaxPrice && c.CoursePrice >= MinPrice);
break;
}
if (SelectedGroup != null && SelectedGroup.Any())
{
Expression<Func<Course, bool>> e = c => SelectedGroup.Contains(c.CourseGroup.Id);
queryable = queryable.Where(expression);
queryable = queryable.Where(c => SelectedGroup.Contains(c.CourseGroup.Id));
}
return queryable;另外,我删除了Include,因为它没有用,如果需要,调用者应该使用它。
https://stackoverflow.com/questions/55974375
复制相似问题