问题描述
在使用的EntityFramework 后,我得到的错误的语句体一个lambda前pression不能转换为前pression树
,试图编译以下code时:
In using the EntityFramework, I get the error "A lambda expression with a statement body cannot be converted to an expression tree
" when trying to compile the following code:
Obj[] myArray = objects.Select(o =>
{
var someLocalVar = o.someVar;
return new Obj() {
Var1 = someLocalVar,
Var2 = o.var2 };
}).ToArray();
我不知道是什么错误意味着最重要的是如何解决它。任何帮助吗?谢谢
I don't know what the error means and most of all how to fix it. Any help? Thanks
推荐答案
是对象
A LINQ到SQL数据库环境?在这种情况下,你只能使用简单的前pressions到=>运算符的右侧。原因是,这些前pressions不被执行,而是被转换为SQL要对数据库执行。
试试这个
Is objects
a Linq-To-SQL database context? In which case, you can only use simple expressions to the right of the => operator. The reason is, these expressions are not executed, but are converted to SQL to be executed against the database.Try this
Arr[] myArray = objects.Select(o => new Obj() {
Var1 = o.someVar,
Var2 = o.var2
}).ToArray();
这篇关于"与语句体一个lambda前pression不能转换为前pression树"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!