From fc09b25bb32aad919b69c822ee19877918d8a7e6 Mon Sep 17 00:00:00 2001 From: Harry McIntyre Date: Thu, 17 Nov 2016 10:33:21 +0000 Subject: [PATCH] Fox for Orderby --- LinqToAnything.Tests/Tests.cs | 14 ++++++++------ LinqToAnything/QueryInfo.cs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/LinqToAnything.Tests/Tests.cs b/LinqToAnything.Tests/Tests.cs index f88d11b..65d961a 100644 --- a/LinqToAnything.Tests/Tests.cs +++ b/LinqToAnything.Tests/Tests.cs @@ -333,14 +333,16 @@ public void CanDoAnOptimizedCount() [Test] public void CanApplyAQueryInfo() { - var queryable = Enumerable.Range(1, 100).Select(i => new SomeEntity() { Name = "User" + i, Index = i }).ToArray().AsQueryable(); + var queryable = Enumerable.Range(1, 100) + .Select(i => new SomeEntity() + { + Name = "User" + i, Index = i + }) + .ToArray().AsQueryable(); - Func> getPageFromDataSource = (info) => - { - return info.ApplyTo(queryable); - }; - var pq = new DelegateQueryable(getPageFromDataSource); + var pq = new DelegateQueryable((info) => info.ApplyTo(queryable)); + Assert.AreEqual(90, pq.OrderByDescending(o => o.Index).Skip(10).Take(1).Single().Index); } diff --git a/LinqToAnything/QueryInfo.cs b/LinqToAnything/QueryInfo.cs index 0c04d7f..81060e7 100644 --- a/LinqToAnything/QueryInfo.cs +++ b/LinqToAnything/QueryInfo.cs @@ -57,7 +57,7 @@ public IQueryable ApplyTo(IQueryable q) var orderBy = qi.OrderBy.Name; if (this.OrderBy.Direction == OrderBy.OrderByDirection.Desc) orderBy += " descending"; - q.OrderBy(orderBy); + q = q.OrderBy(orderBy); } if (qi.Skip > 0) q = q.Skip(qi.Skip);