【发布时间】:2011-03-16 17:14:57
【问题描述】:
我正在尝试将一些内联工作作为 Statement Lambda 注入到 LINQ 查询 select 中,就像这样...
// NOTE: mcontext.Gettype() == System.Data.Linq.DataContext
// Okay - compiles, nothing unusual
var qPeople1 = from ME.tblPeople person in mcontext.tblPeoples
select person;
// ERROR - see below compile Error - Can I retrofit this thing?
var qPeople2 = from ME.tblPeople person in mcontext.tblPeoples
select (() => {
return person;
})();
错误:
错误 2 方法名称 预期 file.cs 166 27 MigrationCore
...不过,我同样很高兴看到 Expression Lambda 首先内联工作。
注意:我知道代码示例的工作是多余的,但我正在寻找基本概念。如果可行,我将对其进行扩展。
【问题讨论】:
-
错误告诉你编译器把它看作是一个函数调用,如果你去掉尾括号会发生什么?
-
@Kjartan:删除括号会出现错误:
The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
标签: c# .net linq lambda datacontext