lambda表达式的顺序导致失败:未知参数。参数名称:parameterExpression实际值为pcount

时间:2014-05-12 21:47:17

标签: vb.net lambda telerik telerik-open-access

当我只是在select语句中翻转Skip / Take和Order By时,我收到错误,但无法看到如何解决此问题。

违规声明:

DBContext.Symbols.OrderBy(Function(obj) obj.Identifier).Skip((StartRec - 1) * EndRec).Take(EndRec).Select(Function(obj) New With {.Id = obj.Id, .Name = obj.Name, .Sector = obj.Sector, .Identifier = obj.Identifier, .isRequest = obj.isRequest, .Direction = obj.Direction, .PlanCount = obj.Plans.Count, .RequestCount = obj.UserSymbols.Where(Function(pcount) pcount.isRequest = 0).Count})

但是,如果我改变它的工作顺序:

DBContext.Symbols.Skip((StartRec - 1) * EndRec).Take(EndRec).OrderBy(Function(obj) obj.Identifier).Select(Function(obj) New With {.Id = obj.Id, .Name = obj.Name, .Sector = obj.Sector, .Identifier = obj.Identifier, .isRequest = obj.isRequest, .Direction = obj.Direction, .PlanCount = obj.Plans.Count, .RequestCount = obj.UserSymbols.Where(Function(pcount) pcount.isRequest = 0).Count})

但是这会导致我对跳过的返回值进行排序,而不是先对它们进行排序。

  

执行'Extent()期间发生异常.OrderBy(obj => obj.Direction).Skip(0).Take(10).Select(obj => new VB $ AnonymousType_0 {{1} 8 [System.Int32,System.String,System.String,System.String,System.Int32,System.Int32,System.Int32,System.Int32]($ obj.Id,$ obj.Name,$ obj.Sector ,$ obj.Identifier,$ obj.isRequest,$ obj.Direction,($ obj.Plans).Count,.Call System.Linq.Enumerable.Count(.Call System.Linq.Enumerable.Where((System.Collections。 Generic.IEnumerable`1 [UserSymbol])$ obj.UserSymbols,.Lambda#Lambda3)))}。Lambda#Lambda3(UserSymbol $ pcount){$ pcount.isRequest == 0}

我理解它在解析RequestCount的lambda语句上遇到了绊脚,并尝试将其移动到对象的属性,但它仍然报告错误。令我困惑的是,我相信它无法解决UserSymbol,但我不确定为什么。我怀疑它丢失了对象引用以正确转换对象类型,尽管不确定原因。

感谢任何帮助。

----更新: 我尝试更改格式以使用以下内容:

8(Id = obj.Id, Name = obj.Name, Sector = obj.Sector, Identifier = obj.Identifier, isRequest = obj.isRequest, Direction = obj.Direction, PlanCount = obj.Plans.Count, RequestCount = Convert(obj.UserSymbols).Where(pcount => (pcount.isRequest == 0)).Count()))'. Failure: Unknown parameter. Parameter name: parameterExpression Actual value was pcount. See InnerException for more details. Complete Expression: .Call System.Linq.Queryable.Select( .Call System.Linq.Queryable.Take( .Call System.Linq.Queryable.Skip( .Call System.Linq.Queryable.OrderBy( .Constant(Extent()), '(.Lambda #Lambda1)), 0), 10), '(.Lambda #Lambda2)) .Lambda #Lambda1(Symbol $obj) { $obj.Direction } .Lambda #Lambda2(Symbol $obj) { .New VB$AnonymousType_0

---更新2:内部异常

  

未知参数。   参数名称:parameterExpression   实际值是pcount。

0 个答案:

没有答案