{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/39063603","id":39063603,"diff_hunk":"@@ -0,0 +1,153 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+using System.Linq;\n+using System.Linq.Expressions;\n+using JetBrains.Annotations;\n+using Microsoft.Data.Entity.Infrastructure;\n+using Microsoft.Data.Entity.Metadata;\n+using Microsoft.Data.Entity.Metadata.Internal;\n+using Microsoft.Data.Entity.Query.Expressions;\n+using Microsoft.Data.Entity.Query.ExpressionVisitors;\n+using Microsoft.Data.Entity.Query.Internal;\n+using Microsoft.Data.Entity.SqlServer;\n+using Microsoft.Data.Entity.Storage;\n+using Microsoft.Data.Entity.Utilities;\n+using Remotion.Linq;\n+using Remotion.Linq.Clauses;\n+\n+namespace Microsoft.Data.Entity.Query\n+{\n+    public class SqlServerQueryModelVisitor : RelationalQueryModelVisitor\n+    {\n+        private const string RowNumberColumnName = \"__RowNumber__\";\n+\n+        private readonly IDbContextOptions _options;\n+\n+        public SqlServerQueryModelVisitor(\n+            [NotNull] IDbContextOptions options,\n+            [NotNull] IModel model,\n+            [NotNull] IQueryOptimizer queryOptimizer,\n+            [NotNull] INavigationRewritingExpressionVisitorFactory navigationRewritingExpressionVisitorFactory,\n+            [NotNull] ISubQueryMemberPushDownExpressionVisitor subQueryMemberPushDownExpressionVisitor,\n+            [NotNull] IQuerySourceTracingExpressionVisitorFactory querySourceTracingExpressionVisitorFactory,\n+            [NotNull] IEntityResultFindingExpressionVisitorFactory entityResultFindingExpressionVisitorFactory,\n+            [NotNull] ITaskBlockingExpressionVisitor taskBlockingExpressionVisitor,\n+            [NotNull] IMemberAccessBindingExpressionVisitorFactory memberAccessBindingExpressionVisitorFactory,\n+            [NotNull] IOrderingExpressionVisitorFactory orderingExpressionVisitorFactory,\n+            [NotNull] IProjectionExpressionVisitorFactory projectionExpressionVisitorFactory,\n+            [NotNull] IEntityQueryableExpressionVisitorFactory entityQueryableExpressionVisitorFactory,\n+            [NotNull] IQueryAnnotationExtractor queryAnnotationExtractor,\n+            [NotNull] IResultOperatorHandler resultOperatorHandler,\n+            [NotNull] IEntityMaterializerSource entityMaterializerSource,\n+            [NotNull] IExpressionPrinter expressionPrinter,\n+            [NotNull] IRelationalMetadataExtensionProvider relationalMetadataExtensionProvider,\n+            [NotNull] IIncludeExpressionVisitorFactory includeExpressionVisitorFactory,\n+            [NotNull] ISqlTranslatingExpressionVisitorFactory sqlTranslatingExpressionVisitorFactory,\n+            [NotNull] ICompositePredicateExpressionVisitorFactory compositePredicateExpressionVisitorFactory,\n+            [NotNull] IQueryFlatteningExpressionVisitorFactory queryFlatteningExpressionVisitorFactory,\n+            [NotNull] IShapedQueryFindingExpressionVisitorFactory shapedQueryFindingExpressionVisitorFactory,\n+            [NotNull] RelationalQueryCompilationContext queryCompilationContext,\n+            [NotNull] IDatabase database,\n+            [CanBeNull] SqlServerQueryModelVisitor parentQueryModelVisitor)\n+            : base(model,\n+                queryOptimizer,\n+                navigationRewritingExpressionVisitorFactory,\n+                subQueryMemberPushDownExpressionVisitor,\n+                querySourceTracingExpressionVisitorFactory,\n+                entityResultFindingExpressionVisitorFactory,\n+                taskBlockingExpressionVisitor,\n+                memberAccessBindingExpressionVisitorFactory,\n+                orderingExpressionVisitorFactory,\n+                projectionExpressionVisitorFactory,\n+                entityQueryableExpressionVisitorFactory,\n+                queryAnnotationExtractor,\n+                resultOperatorHandler,\n+                entityMaterializerSource,\n+                expressionPrinter,\n+                relationalMetadataExtensionProvider,\n+                includeExpressionVisitorFactory,\n+                sqlTranslatingExpressionVisitorFactory,\n+                compositePredicateExpressionVisitorFactory,\n+                queryFlatteningExpressionVisitorFactory,\n+                shapedQueryFindingExpressionVisitorFactory,\n+                queryCompilationContext,\n+                database,\n+                parentQueryModelVisitor)\n+        {\n+            Check.NotNull(options, nameof(options));\n+\n+            _options = options;\n+        }\n+\n+        public override void VisitQueryModel(QueryModel queryModel)\n+        {\n+            base.VisitQueryModel(queryModel);\n+\n+            var extension = _options.FindExtension<SqlServerOptionsExtension>();\n+            if (extension?.RowNumberPaging != null\n+                && extension.RowNumberPaging.Value)\n+            {\n+                foreach (var selectExpression in QueriesBySource.Values)\n+                {\n+                    AdjustForLegacyPaging(selectExpression);\n+                }\n+            }\n+        }\n+\n+        private bool RequiresLegacyPaging(SelectExpression selectExpression)\n+            => selectExpression.Offset.HasValue\n+               && selectExpression.Offset != 0\n+               && !selectExpression.Projection.Any(p => p is RowNumberExpression);\n+\n+        private void AdjustForLegacyPaging(SelectExpression selectExpression)","path":"src/EntityFramework.SqlServer/Query/SqlServerQueryModelVisitor.cs","position":103,"original_position":103,"commit_id":"01873948dfd156269a92066ea6dd7d4486ed6afd","original_commit_id":"01873948dfd156269a92066ea6dd7d4486ed6afd","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"body":"I visit all SelectExpression's in `selectExpression.Tables`. Can subqueries also be nested in `.OrderBy` and `.Predicate`?","created_at":"2015-09-09T16:15:42Z","updated_at":"2015-09-09T16:15:42Z","html_url":"https://github.com/aspnet/EntityFramework/pull/3011#discussion_r39063603","pull_request_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011","_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/39063603"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/3011#discussion_r39063603"},"pull_request":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011","id":44172465,"html_url":"https://github.com/aspnet/EntityFramework/pull/3011","diff_url":"https://github.com/aspnet/EntityFramework/pull/3011.diff","patch_url":"https://github.com/aspnet/EntityFramework/pull/3011.patch","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3011","number":3011,"state":"open","locked":false,"title":"[query] Add support for OFFSET and FETCH on SQL Server 2008","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"body":"Modifies the query structure to include the ROW_NUMBER workaround for limited support of OFFSET and FETCH on SQL 2008,\r\n\r\nAdd legacy paging extension to options builder.\r\n\r\n```c#\r\noptions.UseSqlServer(\"Database=Kilimanjaro2008\").UseRowNumberForPaging()\r\n```\r\n\r\nFix #2180 ","created_at":"2015-09-04T00:19:15Z","updated_at":"2015-09-09T16:15:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3587fca7b9b967c454e4246ee9640051ea43d2f0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011/commits","review_comments_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011/comments","review_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3011/comments","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/01873948dfd156269a92066ea6dd7d4486ed6afd","head":{"label":"natemcmaster:legacy-paging","ref":"legacy-paging","sha":"01873948dfd156269a92066ea6dd7d4486ed6afd","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"repo":{"id":19757095,"name":"EntityFramework","full_name":"natemcmaster/EntityFramework","owner":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/natemcmaster/EntityFramework","description":"","fork":true,"url":"https://api.github.com/repos/natemcmaster/EntityFramework","forks_url":"https://api.github.com/repos/natemcmaster/EntityFramework/forks","keys_url":"https://api.github.com/repos/natemcmaster/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/natemcmaster/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/natemcmaster/EntityFramework/teams","hooks_url":"https://api.github.com/repos/natemcmaster/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/natemcmaster/EntityFramework/events","assignees_url":"https://api.github.com/repos/natemcmaster/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/natemcmaster/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/natemcmaster/EntityFramework/tags","blobs_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/natemcmaster/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/natemcmaster/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/natemcmaster/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/natemcmaster/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/natemcmaster/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/natemcmaster/EntityFramework/subscription","commits_url":"https://api.github.com/repos/natemcmaster/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/natemcmaster/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/natemcmaster/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/natemcmaster/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/natemcmaster/EntityFramework/merges","archive_url":"https://api.github.com/repos/natemcmaster/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/natemcmaster/EntityFramework/downloads","issues_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/natemcmaster/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/natemcmaster/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/natemcmaster/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/natemcmaster/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/natemcmaster/EntityFramework/releases{/id}","created_at":"2014-05-13T21:47:53Z","updated_at":"2014-06-25T23:16:04Z","pushed_at":"2015-09-08T23:36:25Z","git_url":"git://github.com/natemcmaster/EntityFramework.git","ssh_url":"git@github.com:natemcmaster/EntityFramework.git","clone_url":"https://github.com/natemcmaster/EntityFramework.git","svn_url":"https://github.com/natemcmaster/EntityFramework","homepage":null,"size":21612,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"aspnet:dev","ref":"dev","sha":"4132b14ceb77c6f0595f9987af933e0b64a10e16","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","created_at":"2014-01-23T00:52:01Z","updated_at":"2015-09-09T06:42:31Z","pushed_at":"2015-09-09T08:36:45Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":87150,"stargazers_count":2200,"watchers_count":2200,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":646,"mirror_url":null,"open_issues_count":488,"forks":646,"open_issues":488,"watchers":2200,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/3011"},"issue":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/3011"},"comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/3011/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/3011/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/EntityFramework/statuses/01873948dfd156269a92066ea6dd7d4486ed6afd"}}}}