评估的另一种表达内C#表达 [英] Evaluate C# expression inside another expression

查看:109
本文介绍了评估的另一种表达内C#表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个使用的表达式:

I want to use an expression in another one:

Expression<Func<double, double>> f = x => x * x * 27 + blah ... expression with x;

Expression<Func<double, double>> g = y => 3 + 8 * f.Compile()(y) * y * blah... expression with y and f(y);

当发送到LINQ to SQL的,因为f.Compile()是未知的SQL这是行不通的。

This will not work when sent to LINQ to SQL because f.Compile() is unknown to SQL.

您如何评价该变量表达式˚F 无需编译,但仍然使用正常的语法定义先按g

How do you evaluate the expression f on the variable y without compiling it, but still using normal syntax to define g?

我不希望有定义所有先按g 的一些不可读 Expression.Add / Expression.Multiply 等报表。

I don't want to have to define all of g with some unreadable Expression.Add/Expression.Multiply etc. statements.

感谢。

推荐答案

看看调用函数在LINQ查询并的 LINQ扩展项目。 CLinq部分无关你的问题,但它也包括LinqExt库,这正是你寻找的。同样的方法也被 LinqKit 这也为其他的Linq有用的扩展。

Take a look at Calling functions in LINQ queries and LINQ Extensions project. CLinq part is irrelevant to your question, but it also includes LinqExt library, which is just what are you looking for. The same approach is also used by LinqKit which also provides other useful extensions for Linq.

这篇关于评估的另一种表达内C#表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆