From 8f0aae9a43e5b417ee1370e911ec657e2b302954 Mon Sep 17 00:00:00 2001 From: AlekseyMartynov Date: Tue, 6 Aug 2019 16:13:11 +0300 Subject: [PATCH] Disable PaginateViaPrimaryKey without Take (#375) --- .../PaginateViaPrimaryKeyTests.cs | 15 ++++++++++++++- .../DataSourceLoaderImpl.cs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs b/net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs index 26c5f76e..d553a239 100644 --- a/net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs +++ b/net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs @@ -93,12 +93,25 @@ public void ActiveForFirstPage() { Assert.Contains(".Select(obj => new AnonType`1", loadOptions.ExpressionLog[0]); } + [Fact] + public void DisabledWithoutTake() { + var loadOptions = new SampleLoadOptions { + SuppressGuardNulls = true, + PaginateViaPrimaryKey = true + }; + + DataSourceLoader.Load(new object[0], loadOptions); + + Assert.NotEmpty(loadOptions.ExpressionLog); + Assert.DoesNotContain(loadOptions.ExpressionLog, line => line.Contains(".Select")); + } + [Fact] public void RequiresPrimaryKey() { var error = Record.Exception(delegate { DataSourceLoader.Load(new string[0], new SampleLoadOptions { PaginateViaPrimaryKey = true, - Skip = 1 + Take = 1 }); }); Assert.True(error is InvalidOperationException); diff --git a/net/DevExtreme.AspNet.Data/DataSourceLoaderImpl.cs b/net/DevExtreme.AspNet.Data/DataSourceLoaderImpl.cs index a5bff384..c14636c1 100644 --- a/net/DevExtreme.AspNet.Data/DataSourceLoaderImpl.cs +++ b/net/DevExtreme.AspNet.Data/DataSourceLoaderImpl.cs @@ -66,7 +66,7 @@ public LoadResult Load() { Expression loadExpr; - if(!deferPaging && Context.PaginateViaPrimaryKey) { + if(!deferPaging && Context.PaginateViaPrimaryKey && Context.Take > 0) { if(!Context.HasPrimaryKey) { throw new InvalidOperationException(nameof(DataSourceLoadOptionsBase.PaginateViaPrimaryKey) + " requires a primary key."