Skip to content

Commit

Permalink
Disable PaginateViaPrimaryKey without Take (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyMartynov authored Aug 6, 2019
1 parent 6d97370 commit 8f0aae9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion net/DevExtreme.AspNet.Data.Tests/PaginateViaPrimaryKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/DevExtreme.AspNet.Data/DataSourceLoaderImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 8f0aae9

Please sign in to comment.