无法使用“跳过”在 LINQ 查询中
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终只是使用 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.