为什么 GetPaged() 执行两次数据库调用?
我对亚音速有点陌生(即评估 3.0.0.3),并且在 GetPaged(int pageIndex, int pageSize) 中遇到了奇怪的行为。当我执行该方法时,它会执行两次 SQL 调用。有什么想法吗?
详细信息
假设我有一个包含 200 行的“文化”表。在我的代码中,我做了类似的事情...
var sonicCollection = from c in RTE.Culture.GetPaged(1, 25)
select c;
现在,我希望这会执行一个查询,返回我的文化表中的前 25 个条目。当我观看 SQL Profiler 时,我看到运行了两个查询。
首先是这个——
SELECT [dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
然后是这个——
SELECT *
FROM (SELECT ROW_NUMBER() OVER (
ORDER BY cultureID ASC) AS Row,
[dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
)
AS PagedResults
WHERE Row >= 1 AND Row <= 25
我希望第二个查询能够顺利通过,因为它返回了我礼貌地请求的亚音速的 25 行。然而,第一个查询似乎返回 200 行(至少根据 SQL 探查器)。
有什么想法吗?
I'm a bit new to subsonic (i.e. evaluating 3.0.0.3) and have come across a strange behavior in GetPaged(int pageIndex, int pageSize). When I execute the method it does two SQL calls. Any ideas why ?
Details
Lets say I have a "Cultures" table with 200 rows. In my code I do something like ...
var sonicCollection = from c in RTE.Culture.GetPaged(1, 25)
select c;
Now, I would expect this executes a single query returning the first 25 entries in my cultures table. When I watch SQL profiler I see two queries run by.
First this--
SELECT [dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
Then This--
SELECT *
FROM (SELECT ROW_NUMBER() OVER (
ORDER BY cultureID ASC) AS Row,
[dbo].[Cultures].[cultureCode], [dbo].[Cultures].[cultureName]
FROM [dbo].[Cultures]
)
AS PagedResults
WHERE Row >= 1 AND Row <= 25
I expect the 2nd query to roll by, as it is the one returning the 25 rows I politely requested of subsonic. The first query, however, appears to return 200 rows (at least according to SQL profiler).
Any ideas what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是代码中的错误。该代码实际上查询每条记录,然后迭代每条记录以获取计数。我在 github 存储库中创建了一个问题:
https://github.com/subsonic/SubSonic-3.0/issues/259
您可以轻松下载源代码、修复问题并重新编译。我已经这样做了,它解决了我的问题。
It's a bug in the code. The code actually queries every record and then iterates over each one for the count. I've created an issue in the github repo here:
https://github.com/subsonic/SubSonic-3.0/issues/259
You can download the source, fix the issue and recompile pretty easily. I've done this and its fixed my issue.
您只想使用 RTE.Culture.GetPaged() - 它为您运行分页查询。
You just want to use RTE.Culture.GetPaged() - it runs the paged query for you.