表达式树复制或转换
如何将 Form 的 ExpressionTree 转换
Expression<Func<POCO1, bool>> exp = p => p.Age > 50;
为
Expression<Func<POCO2, bool>> exp2 = p => p.Age > 50;
其中 POCO1 和 POCO2 是 C# 对象并且都具有 Int32 Age 属性
How to convert a ExpressionTree of form
Expression<Func<POCO1, bool>> exp = p => p.Age > 50;
to
Expression<Func<POCO2, bool>> exp2 = p => p.Age > 50;
where POCO1 and POCO2 are C# objects and both have Int32 Age property
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,您可以创建自定义表达式访问者来替换参数引用和补丁成员访问表达式
well, you can make custom expression visitor that will replace parameter references and patch member access expressions
粗略步骤:
正如我猜测的那样,您在这里获得的类型是一个没有 setter 的属性。
所以你必须构建一个新的表达式
的方法
这是手动构建 x = 的 linq 表达式 > x.Child == itemToCompare.Child
Rough Steps:
The type you get here is a property without setter as I guessed.
So you must build a new expression
Here is the way
manually build linq expression for x => x.Child == itemToCompare.Child
理想情况下 - 你不会。创建一个描述 Age 属性的接口,并构建引用 that 的表达式。如果您无法修改 POCO 类型,请使用像 Go 这样的语言,其中接口是隐式的:-)。
Ideally - you don't. Make an interface that describes the Age property, and build the expression to refer to that. If you can't modify the POCO types, use a language like Go, where interfaces are implicit :-).