Need assistance with a LINQ query created using the Dynamic LINQ Library?

dynamic-linq linq vb.net

Question

Forgive my ignorance on this. I have this LINQ Query: 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()

As you can see it is a LIST(OF ). Here is the definition of the bikersList:

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

I need to be able to sort, so was going to use the Dynamic LINQ Library. So I added it to my project Imported System.Linq.Dynamic and tried to use this code:

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

But now I am getting the blue scwiggly line under:

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

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments." Over the "NEW" I get an error " ')'expected."

Would someone please tell me what I am doing wrong. Thank You

1
2
3/31/2011 8:51:08 PM

Accepted Answer

You're mixing up 'extension method' syntax with 'query syntax'.

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

Or

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()
1
3/31/2011 8:48:49 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow