Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 6cfe502

Browse files
committed
Change OrderBy to orderByProperties
1 parent 0d4d9ea commit 6cfe502

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,11 @@ public virtual SqlExpression<T> OrderBy(long columnIndex)
683683
public virtual SqlExpression<T> UnsafeOrderBy(string orderBy)
684684
{
685685
orderByProperties.Clear();
686-
this.orderBy = string.IsNullOrEmpty(orderBy)
687-
? null
688-
: "ORDER BY " + orderBy;
686+
if (!string.IsNullOrEmpty(orderBy))
687+
{
688+
orderByProperties.Add(orderBy);
689+
}
690+
BuildOrderByClauseInternal();
689691
return this;
690692
}
691693

src/ServiceStack.OrmLite/IOrmLiteConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class OrmLiteConverter : IOrmLiteConverter
4040
public IOrmLiteDialectProvider DialectProvider { get; set; }
4141

4242
/// <summary>
43-
/// SQL Column Definiton used in CREATE Table.
43+
/// SQL Column Definition used in CREATE Table.
4444
/// </summary>
4545
public abstract string ColumnDefinition { get; }
4646

tests/ServiceStack.OrmLite.Tests/OrderByTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using NUnit.Framework;
33
using ServiceStack.OrmLite.Tests.Expression;
4+
using ServiceStack.Text;
45

56
namespace ServiceStack.OrmLite.Tests
67
{
@@ -29,5 +30,28 @@ public void Can_order_by_random()
2930
Assert.That(!rowIds1.SequenceEqual(rowIds2));
3031
}
3132
}
33+
34+
[Test]
35+
public void Can_OrderBy_and_ThenBy()
36+
{
37+
using (var db = OpenDbConnection())
38+
{
39+
db.DropAndCreateTable<LetterFrequency>();
40+
41+
db.Insert(new LetterFrequency {Letter = "C" });
42+
db.Insert(new LetterFrequency {Letter = "C" });
43+
db.Insert(new LetterFrequency {Letter = "B" });
44+
db.Insert(new LetterFrequency {Letter = "A" });
45+
46+
var q = db.From<LetterFrequency>();
47+
q.OrderBy(nameof(LetterFrequency.Letter))
48+
.ThenBy(nameof(LetterFrequency.Id));
49+
50+
var tracks = db.Select(q);
51+
52+
Assert.That(tracks.First().Letter, Is.EqualTo("A"));
53+
Assert.That(tracks.Last().Letter, Is.EqualTo("C"));
54+
}
55+
}
3256
}
3357
}

0 commit comments

Comments
 (0)