gpt4 book ai didi

c# - 表达式> predicate=null;在 where condition(query.Where(predicate)) 中抛出错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:47 26 4
gpt4 key购买 nike

 Expression<Func<PartJoinTable, bool>> predicate = null;

var query2 = query.Join(partJoinTableRepository.GetPartJoinQuery(),
"x.PartID", "PartID", "inner" + row + "", null);
foreach (var item1 in query)
{
list.Add(new PartJoinTable
{
ProductTypeId = item1.x.ProductTypeId,
PartId = item1.x.PartId
});

}
predicate = PredicateBuilder.True(list.AsQueryable());


if (typeid=="3")
{
if (row == 0)
{
predicate1 = predicate1.And(z => cpaclassids.Contains(z.x.ProductTypeId.ToString()));
}
else
{
predicate = predicate.And(x => cpaclassids.Contains(x.ProductTypeId.ToString()));
}
}
row++;
}
int lst1 = query.Where(predicate).Select(x => x).Distinct().ToList().Count();

Cannot convert from 'System.Linq.Expressions.Expression>' to 'System.Func<, bool>'

我无法检索结果,因为当我声明变量 Expression<Func<PartJoinTable, bool>> predicate = null; 时显示上述错误

最佳答案

回答

Expression> predicate=null; throws error in where condition(query.Where(predicate))

if (predicate != null)
query = query.Where(predicate);

int lst1 = query.Distinct().Count();

仅在 where 子句存在时添加它。在 .Count() 之前使用 .ToList() 可以将数据库中的每一行投影到内存中。

关于c# - 表达式<Func<PartJoinTable, bool>> predicate=null;在 where condition(query.Where(predicate)) 中抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51856730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com