无法使用“跳过”在 LINQ 查询中

发布于 2024-08-10 23:32:24 字数 989 浏览 6 评论 0原文

我有一个 linq 查询,需要在其中专门执行左连接。但是,当我尝试在查询上提交 lambda Skip 函数时,它会出错,并表示无法在带有联接的 linq 查询上执行跳过。

这是查询(skip 变量是函数的参数,clientDB 是数据上下文):

            Dim questionsQuery = From helpQuestion As HelpQuestion In clientDB.HelpQuestions _
                             Group Join helpCat As HelpCategory In clientDB.HelpCategories _
                             On helpCat.ROW_ID Equals helpQuestion.CATEGORY_ID Into helpGroup = Group _
                             From helpCategory In helpGroup.DefaultIfEmpty() _
                             Where helpQuestion.DISPLAY_DESK _
                             Order By helpQuestion.ROW_ID Descending _
                             Select helpQuestion.ROW_ID, helpQuestion.EMAIL, helpQuestion.FIRST_NAME, helpQuestion.LAST_NAME, helpQuestion.QUESTION, helpQuestion.CREATED, helpQuestion.RESPONSE, helpCategory.CATEGORY_NAME

        If skip > 0 Then
            questionsQuery = questionsQuery.Skip(skip)
        End If

I have a linq query in which I need to specifically do a left join. However when I attempt to commit a lambda Skip function on the query it errors and says that the skip cannot be performed on a linq query with a join.

Here's the query (the skip variable is a parameter into the function and clientDB is the datacontext):

            Dim questionsQuery = From helpQuestion As HelpQuestion In clientDB.HelpQuestions _
                             Group Join helpCat As HelpCategory In clientDB.HelpCategories _
                             On helpCat.ROW_ID Equals helpQuestion.CATEGORY_ID Into helpGroup = Group _
                             From helpCategory In helpGroup.DefaultIfEmpty() _
                             Where helpQuestion.DISPLAY_DESK _
                             Order By helpQuestion.ROW_ID Descending _
                             Select helpQuestion.ROW_ID, helpQuestion.EMAIL, helpQuestion.FIRST_NAME, helpQuestion.LAST_NAME, helpQuestion.QUESTION, helpQuestion.CREATED, helpQuestion.RESPONSE, helpCategory.CATEGORY_NAME

        If skip > 0 Then
            questionsQuery = questionsQuery.Skip(skip)
        End If

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

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

发布评论

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

评论(1

‖放下 2024-08-17 23:32:24

我最终只是使用 questionsQuery.ToList() 将其转换为列表。这不是最好的解决方案,因为 ToList 函数将整个结果集返回到内存列表中,但它有效。

I ended up just converting this to a list using questionsQuery.ToList(). Not the best solution because the ToList function returns the entire result set to an in-memory list, but it worked.

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