Skip to content

Commit

Permalink
fixed error, where Select returned 0 as total.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanmeissner committed Jun 26, 2020
1 parent 7e6cdb0 commit 18e4c24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions DCCS.Data.Source.Tests/ResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void Should_map_data()
.Select(entry => new DummyDTO { Name = entry.Name, Length = (entry.Name ?? "").Length });

Assert.IsInstanceOf(typeof(DummyDTO), sut.Data.First());
Assert.AreEqual(data.Count(), sut.Count);
Assert.AreEqual(data.Count(), sut.Total);
}

[Test]
Expand Down Expand Up @@ -172,6 +174,8 @@ public void Should_not_sort_if_unchecked()
Assert.AreEqual("1", sorted[1].Name);
Assert.AreEqual("7", sorted[2].Name);

Assert.AreEqual(3, sut.Total);

}

[Test]
Expand Down
17 changes: 17 additions & 0 deletions DCCS.Data.Source/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ public override void SetData(IQueryable<T> data, bool sort, bool page)
base.SetData(data, sort: sort, page: page);
}

public new Result<DTO> Select<DTO>(Expression<Func<T, DTO>> predicate)
{
var result = new Result<DTO>(new Params
{
Count = Count,
OrderBy = OrderBy,
Desc = Desc,
Page = Page,
})
{
Data = Data.AsQueryable().Select(predicate)
};
result.Total = this.Total;

return result;
}

public int Total { get; set; }
}
}
6 changes: 3 additions & 3 deletions DCCS.Data.Source/ResultWithoutTotal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public virtual void SetData(IQueryable<T> data, bool sort, bool page)
}
}

public Result<DTO> Select<DTO>(Expression<Func<T, DTO>> predicate)
public virtual ResultWithoutTotal<DTO> Select<DTO>(Expression<Func<T, DTO>> predicate)
{
return new Result<DTO>(new Params
return new ResultWithoutTotal<DTO>(new Params
{
Count = Count,
OrderBy = OrderBy,
Desc = Desc,
Page = Page
Page = Page,
})
{
Data = Data.AsQueryable().Select(predicate)
Expand Down

0 comments on commit 18e4c24

Please sign in to comment.