2011-03-31 62 views
1

請原諒我對此的無知。 我有這樣的LINQ查詢: 昏暗ngBikersDataContext作爲新CarBikeWalkDataContext需要使用動態LINQ庫的LINQ查詢幫助

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)) 

我需要能夠排序,所以要使用動態LINQ庫。所以,我把它添加到我的項目進口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

您在'查詢語法'中混合使用'擴展方法'語法。

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() 
+0

謝謝你洙多! – 2011-03-31 21:13:47