This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-4
lines changed
tests/ServiceStack.OrmLite.Tests Expand file tree Collapse file tree 3 files changed +30
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11using System . Linq ;
22using NUnit . Framework ;
33using ServiceStack . OrmLite . Tests . Expression ;
4+ using ServiceStack . Text ;
45
56namespace 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}
You can’t perform that action at this time.
0 commit comments