2

当我在 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 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_08[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,但我不知道为什么。我怀疑它会丢失对象引用以正确转换对象类型,尽管不确定原因。

任何帮助表示赞赏。

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

From obj In DBContext.Symbols Order By obj.Identifier Skip ((StartRec - 1) * EndRec) Take EndRec Select 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}

---更新2:内部异常

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

4

0 回答 0