c# - 始终返回 true 的替代表达式
问题描述
我正在尝试构建一个动态Expression<Func<User, bool>>
以在 MongoDB LINQ Where 查询过滤器中使用。
我正在使用 if-else 块动态构建表达式,并使用 Albahari PredicateBuilder.And()
( http://www.albahari.com/nutshell/predicatebuilder.aspx ) 组合表达式。
PredicateBuilder.True<T>()
在这些块中使用AND
会导致 MongoDB LINQ 转换器抛出此异常:
Unsupported filter: Invoke(f => True, {document}).
我可以用什么其他表达式格式来表达user=>true
某种逻辑,以便 MongoDB LINQ 提供程序接受它?
注意:我尝试使用 return Expression.Lambda(Expression.Constant(true), Expression.Parameter(type, "_")); 我在另一篇 SO 帖子(https://stackoverflow.com/a/36773532/10811808)中看到,但我不知道如何将此 ConstantExpression 转换为 Expression>。
解决方案
推荐阅读
- sql-server - 在 SQL Server 中创建一个接受参数 (user_name) 并返回表的函数
- bash - 如何并行 bash for 循环
- reactjs - shadow dom 内的 Material ui 缺少用于后续调用 webcomponent 的样式
- wordpress - 如何在 Wordpress 的页面模板中显示简短的帖子信息?
- python - 加快嵌套循环比较
- php - 如何将 $destination 添加到 file_get_contents
- javascript - Redux 按索引读取数组元素
- python - 根据找到的最后一位数字拆分列
- amazon-web-services - CloudFormation GUI 参数覆盖
- powershell - PowerShell 将箭头键绑定到命令历史搜索