需要有关使用动态 LINQ 库的 LINQ 查询的帮助

发布于 2024-10-28 23:58:37 字数 1423 浏览 0 评论 0原文

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2024-11-04 23:58:37

您将“扩展方法”语法与“查询语法”混淆了。

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文