我有以下代码:
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
我该如何解决?