原谅我对此的无知。 我有这个LINQ查询: Dim ngBikersDataContext As New CarBikeWalkDataContext
bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _
.M_Name = c.M_Name, _
.L_Name = c.L_Name _
}).ToList()
你可以看到它是一个列表(OF)。以下是bikersList的定义:
Dim bikersList As List(Of Bikers) = TryCast(HttpContext.Current.Session("Bikers"), List(Of Bikers))
我需要能够排序,所以打算使用Dynamic LINQ Library。所以我将它添加到我的项目Imported System.Linq.Dynamic并尝试使用此代码:
bikersList = (ngBikersDataContext.Reg_Bikers _
.OrderBy(SortExpression) _
.Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _
.M_Name = c.M_Name, _
.L_Name = c.L_Name _
}).ToList()
但现在我得到了蓝色的scwiggly线:
ngBikersDataContext.Reg_Bikers _
.OrderBy(SortExpression) _
.Select
错误“重载解析失败,因为无法访问'选择'接受此数量的参数。” 超过“新”我得到一个错误“')'预期。”
有人请告诉我我做错了什么。 谢谢
答案 0 :(得分:1)
您将'扩展方法'语法与'查询语法'混合在一起。
bikersList = (ngBikersDataContext.Reg_Bikers _
.OrderBy(SortExpression) _
.Select(Function(c) New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _
.M_Name = c.M_Name, _
.L_Name = c.L_Name _
})).ToList()
或者
bikersList = (From c in ngBikersDataContext.Reg_Bikers.OrderBy(SortExpression) _
Select b = New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _
.M_Name = c.M_Name, _
.L_Name = c.L_Name _
}).ToList()