【问题标题】:Need help with a LINQ Query using the Dynamic LINQ Library在使用动态 LINQ 库的 LINQ 查询方面需要帮助
【发布时间】:2011-03-31 20:42:48
【问题描述】:

请原谅我对此的无知。 我有这个 LINQ 查询: 将 ngBikersDataContext 调暗为新的 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()

但现在我得到了下面的蓝色波浪线:

                    ngBikersDataContext.Reg_Bikers _
                    .OrderBy(SortExpression) _
                    .Select

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

有人能告诉我我做错了什么吗? 谢谢你

【问题讨论】:

    标签: vb.net linq dynamic-linq


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多