基于另一个 LINQ 表达式和值构建特定的 LINQ 表达式
如果我有以下形式的 LINQ 表达式:
Expression<Func<MyClass, string, bool>> filterExpression = (x, filterVal) => x.DisplayName.Contains(filterVal);
有什么方法可以获取下面的表达式吗?
Expression<Func<MyClass, bool>> filter = x => x.DisplayName.Contains("John");
我需要在 Linq-to-EntitiesWhere 调用中使用第二个表达式。
If I've got a LINQ expression of the form:
Expression<Func<MyClass, string, bool>> filterExpression = (x, filterVal) => x.DisplayName.Contains(filterVal);
Is there any way I can get to the expression below?
Expression<Func<MyClass, bool>> filter = x => x.DisplayName.Contains("John");
I need to use the second expression in a Linq-to-Entities Where call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要编写一个
ExpressionVisitor
用ConstantExpression
替换ParameterExpression
。它看起来像
You need to write an
ExpressionVisitor
that replaces theParameterExpression
with aConstantExpression
.It would look something like
如果我解决它的方式有用的话:
In case it's useful the way I solved it was: