致电Linq Expressions

时间:2014-10-14 16:03:42

标签: c# linq

我有一个表达词典:

        private static Dictionary<string, Expression<Func<Client, string, decimal?>>> decimalEx;

        public static Dictionary<string, Expression<Func<Client, string, decimal?>>> DecimalEx
        {
            get
            {
                if (decimalEx == null)
                {
                    decimalEx =
                       new Dictionary<string, Expression<Func<Client, decimal?>>> 
                      {
                        { "First", (client) => [...] },
[...]

然后从另一个表达式(顺便说一下LinqKit表达式),我想称之为

  Expression<Func<Client, ClientFull>> qu =
                    (client) =>
first =  DecimalEx["First"].Invoke(client),
[...]

但是我收到了这个错误:无法转换类型&System; System.Linq.Expressions.MethodCallExpressionN&#39;输入&#39; System.Linq.Expressions.LambdaExpression&#39;

但是,如果我之前在变量中设置表达式,它可以工作:

var proxy =  DecimalEx["First"];

Expression<Func<Client, ClientFull>> qu =
                    (client) =>
first =  proxy.Invoke(client),
[...]

是否可以直接调用表达式而无需使用变量?

1 个答案:

答案 0 :(得分:1)

不要使用查询语法,请使用方法语法:

var query = data.Select(calcFunction);