This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
src/ServiceStack.OrmLite/Expressions
tests/ServiceStack.OrmLite.Tests/UseCase Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -457,7 +457,18 @@ public virtual SqlExpression<T> GroupBy(string groupBy)
457
457
return this ;
458
458
}
459
459
460
- public virtual SqlExpression < T > GroupBy < TKey > ( Expression < Func < T , TKey > > keySelector )
460
+ public virtual SqlExpression < T > GroupBy < Table > ( Expression < Func < Table , object > > keySelector )
461
+ {
462
+ sep = string . Empty ;
463
+ useFieldName = true ;
464
+
465
+ var groupByKey = Visit ( keySelector ) ;
466
+ StripAliases ( groupByKey as SelectList ) ; // No "AS ColumnAlias" in GROUP BY, just the column names/expressions
467
+
468
+ return GroupBy ( groupByKey . ToString ( ) ) ;
469
+ }
470
+
471
+ public virtual SqlExpression < T > GroupBy ( Expression < Func < T , object > > keySelector )
461
472
{
462
473
sep = string . Empty ;
463
474
useFieldName = true ;
Original file line number Diff line number Diff line change 1
- using NUnit . Framework ;
1
+ using System . Linq ;
2
+ using NUnit . Framework ;
2
3
using ServiceStack . OrmLite . Tests . Support ;
3
4
using ServiceStack . Text ;
4
5
@@ -44,5 +45,20 @@ public void Can_Order_by_Property_Alias()
44
45
Assert . That ( result [ 1993 ] , Is . EqualTo ( 2 ) ) ;
45
46
}
46
47
}
48
+
49
+ [ Test ]
50
+ public void Can_Select_joined_table_with_Alias ( )
51
+ {
52
+ using ( var db = CreateArtistAndTrackTablesWithData ( OpenDbConnection ( ) ) )
53
+ {
54
+ var tracksByYear = db . Dictionary < string , int > ( db . From < Track > ( )
55
+ . Join < Artist > ( )
56
+ . GroupBy < Artist > ( x => x . Name )
57
+ . Select < Artist > ( x => new { x . Name , Count = Sql . Count ( "*" ) } ) ) ;
58
+
59
+ Assert . That ( tracksByYear . Count , Is . EqualTo ( 4 ) ) ;
60
+ Assert . That ( tracksByYear . Map ( x => x . Value ) . Sum ( ) , Is . EqualTo ( 8 ) ) ;
61
+ }
62
+ }
47
63
}
48
64
}
You can’t perform that action at this time.
0 commit comments