{"action":"created","issue":{"url":"https://api.github.com/repos/sqlkata/querybuilder/issues/61","repository_url":"https://api.github.com/repos/sqlkata/querybuilder","labels_url":"https://api.github.com/repos/sqlkata/querybuilder/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/sqlkata/querybuilder/issues/61/comments","events_url":"https://api.github.com/repos/sqlkata/querybuilder/issues/61/events","html_url":"https://github.com/sqlkata/querybuilder/issues/61","id":313721758,"number":61,"title":"Chunk throws exception on second page","user":{"login":"rocksthehouse","id":22393135,"avatar_url":"https://avatars3.githubusercontent.com/u/22393135?v=4","gravatar_id":"","url":"https://api.github.com/users/rocksthehouse","html_url":"https://github.com/rocksthehouse","followers_url":"https://api.github.com/users/rocksthehouse/followers","following_url":"https://api.github.com/users/rocksthehouse/following{/other_user}","gists_url":"https://api.github.com/users/rocksthehouse/gists{/gist_id}","starred_url":"https://api.github.com/users/rocksthehouse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rocksthehouse/subscriptions","organizations_url":"https://api.github.com/users/rocksthehouse/orgs","repos_url":"https://api.github.com/users/rocksthehouse/repos","events_url":"https://api.github.com/users/rocksthehouse/events{/privacy}","received_events_url":"https://api.github.com/users/rocksthehouse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-12T13:14:15Z","updated_at":"2018-04-12T14:18:05Z","closed_at":null,"author_association":"NONE","body":"I am using 1.0.0-beta-458 and with the following simple code I get an exception when it tries to return the second page of results:\r\n\r\nvar query = new Query(\"dbo.MyTable\");\r\n\r\nvar db = new QueryFactory(connection, new SqlServerCompiler());\r\n\r\ndb.Query(query).Chunk(2, (rows, page) =>\r\n{\r\n});\r\n\r\nIt appears to be down to the code which adds the fake raw SQL clause (there is a comment about this in the code) which works for the first page as it includes a TOP clause. However, the second page query doesn't include this and so the generated SQL is invalid (there is a comma before the * in the second select):\r\n\r\nSELECT * FROM (SELECT , *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS [row_num] FROM [dbo].[MyTable]) AS [subquery] WHERE [row_num] BETWEEN @p0 AND @p1"},"comment":{"url":"https://api.github.com/repos/sqlkata/querybuilder/issues/comments/380821490","html_url":"https://github.com/sqlkata/querybuilder/issues/61#issuecomment-380821490","issue_url":"https://api.github.com/repos/sqlkata/querybuilder/issues/61","id":380821490,"user":{"login":"rocksthehouse","id":22393135,"avatar_url":"https://avatars3.githubusercontent.com/u/22393135?v=4","gravatar_id":"","url":"https://api.github.com/users/rocksthehouse","html_url":"https://github.com/rocksthehouse","followers_url":"https://api.github.com/users/rocksthehouse/followers","following_url":"https://api.github.com/users/rocksthehouse/following{/other_user}","gists_url":"https://api.github.com/users/rocksthehouse/gists{/gist_id}","starred_url":"https://api.github.com/users/rocksthehouse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rocksthehouse/subscriptions","organizations_url":"https://api.github.com/users/rocksthehouse/orgs","repos_url":"https://api.github.com/users/rocksthehouse/repos","events_url":"https://api.github.com/users/rocksthehouse/events{/privacy}","received_events_url":"https://api.github.com/users/rocksthehouse/received_events","type":"User","site_admin":false},"created_at":"2018-04-12T14:18:05Z","updated_at":"2018-04-12T14:18:05Z","author_association":"NONE","body":"In SqlServerCompiler if I add an else block to the `if (limitOffset != null && limitOffset.HasLimit() && !limitOffset.HasOffset()) {}` block and remove the clause at index 0 if the clause component was the fake one that was added previously then it fixes it for me.\r\n\r\nBut I'm not sure what the correct logic is to determine whether it is safe to remove it. Just removing it in the else if the clause is a RawColumn with component = \"select\", Expression=\"\" and Binding with limit in it probably not selective enough."}}
{"actor":{"display_login":"rocksthehouse"}}