2

原谅我对此的无知。我有这个 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()

如您所见,它是一个 LIST(OF)。这是 bikersList 的定义:

Dim bikersList As List(Of Bikers) = TryCast(HttpContext.Current.Session("Bikers"), List(Of Bikers))

我需要能够排序,所以打算使用动态 LINQ 库。所以我将它添加到我的项目 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

出现错误“重载解析失败,因为没有可访问的 'Select' 接受此数量的参数。” 在“NEW”上,我收到一个错误“')'expected。”

有人请告诉我我做错了什么。谢谢你

4

1 回答 1

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()
于 2011-03-31T20:48:49.917 回答