LINQ:使用主体编写表达式以返回IQueryable

时间:2019-03-28 10:01:11

标签: c# linq iqueryable

我有以下代码:

Func<ObjectA, ObjectB> selector = item =>
{
    var b = new ObjectB();
    ...
    return b;
};

var result = items.Select(selector);

此代码返回IEnumerable<ObjectB>,但我需要IQueryable<ObjectB>

据我了解,我需要做Expression

如果我接下来做:

Expression<Func<ObjectA, ObjectB>> selector = item =>
{
    var b = new ObjectB();
    ...
    return b;
};

var result = items.Select(selector);

显示错误A lambda expression with a statement body cannot be converted to an expression tree

我该如何解决?

0 个答案:

没有答案