Skip to content
Permalink
Browse files

Change OrderBy to orderByProperties

  • Loading branch information...
mythz committed Jun 5, 2019
1 parent 0d4d9ea commit 6cfe502d3e9c1d561efa067a5b333ce0bfc1d67a
@@ -683,9 +683,11 @@ public virtual SqlExpression<T> OrderBy(long columnIndex)
public virtual SqlExpression<T> UnsafeOrderBy(string orderBy)
{
orderByProperties.Clear();
this.orderBy = string.IsNullOrEmpty(orderBy)
? null
: "ORDER BY " + orderBy;
if (!string.IsNullOrEmpty(orderBy))
{
orderByProperties.Add(orderBy);
}
BuildOrderByClauseInternal();
return this;
}

@@ -40,7 +40,7 @@ public abstract class OrmLiteConverter : IOrmLiteConverter
public IOrmLiteDialectProvider DialectProvider { get; set; }

/// <summary>
/// SQL Column Definiton used in CREATE Table.
/// SQL Column Definition used in CREATE Table.
/// </summary>
public abstract string ColumnDefinition { get; }

@@ -1,6 +1,7 @@
using System.Linq;
using NUnit.Framework;
using ServiceStack.OrmLite.Tests.Expression;
using ServiceStack.Text;

namespace ServiceStack.OrmLite.Tests
{
@@ -29,5 +30,28 @@ public void Can_order_by_random()
Assert.That(!rowIds1.SequenceEqual(rowIds2));
}
}

[Test]
public void Can_OrderBy_and_ThenBy()
{
using (var db = OpenDbConnection())
{
db.DropAndCreateTable<LetterFrequency>();

db.Insert(new LetterFrequency {Letter = "C" });
db.Insert(new LetterFrequency {Letter = "C" });
db.Insert(new LetterFrequency {Letter = "B" });
db.Insert(new LetterFrequency {Letter = "A" });

var q = db.From<LetterFrequency>();
q.OrderBy(nameof(LetterFrequency.Letter))
.ThenBy(nameof(LetterFrequency.Id));

var tracks = db.Select(q);

Assert.That(tracks.First().Letter, Is.EqualTo("A"));
Assert.That(tracks.Last().Letter, Is.EqualTo("C"));
}
}
}
}

0 comments on commit 6cfe502

Please sign in to comment.
You can’t perform that action at this time.