@@ -856,6 +856,24 @@ public override bool Equals(object obj)
856
856
}
857
857
}
858
858
859
+ private class JoinSelectResults2
860
+ {
861
+ // From TableA
862
+ public int Id { get ; set ; }
863
+ public bool Bool { get ; set ; }
864
+ public string Name { get ; set ; }
865
+
866
+ // From TableB
867
+ public int TableBId { get ; set ; }
868
+ public string TableBName { get ; set ; }
869
+
870
+ public override bool Equals ( object obj )
871
+ {
872
+ var other = ( JoinSelectResults2 ) obj ;
873
+ return Id == other . Id && Bool == other . Bool && Name == other . Name && TableBId == other . TableBId && TableBName == other . TableBName ;
874
+ }
875
+ }
876
+
859
877
[ Test ]
860
878
public void Can_select_entire_tables ( )
861
879
{
@@ -870,21 +888,38 @@ public void Can_select_entire_tables()
870
888
db . Insert ( new TableB { Id = 2 , TableAId = 2 , Name = "NameB2" } ) ;
871
889
db . Insert ( new TableB { Id = 3 , TableAId = 2 , Name = "NameB3" } ) ;
872
890
873
- var q = db . From < TableA > ( )
874
- . Join < TableB > ( )
875
- . Select < TableA , TableB > ( ( a , b ) => new { a , b . TableAId } )
876
- . OrderBy ( x => x . Id ) ;
877
-
878
891
try
879
892
{
880
- var rows = db . Select < JoinSelectResults1 > ( q ) ;
881
- var expected = new [ ]
893
+ // Select all columns from TableA
894
+
895
+ var q1 = db . From < TableA > ( )
896
+ . Join < TableB > ( )
897
+ . Select < TableA , TableB > ( ( a , b ) => new { a , b . TableAId } )
898
+ . OrderBy ( x => x . Id ) ;
899
+
900
+ var rows1 = db . Select < JoinSelectResults1 > ( q1 ) ;
901
+ var expected1 = new [ ]
882
902
{
883
903
new JoinSelectResults1 { Id = 1 , Bool = false , Name = "NameA1" , TableAId = 1 } ,
884
904
new JoinSelectResults1 { Id = 2 , Bool = true , Name = "NameA2" , TableAId = 2 } ,
885
905
new JoinSelectResults1 { Id = 2 , Bool = true , Name = "NameA2" , TableAId = 2 } ,
886
906
} ;
887
- Assert . That ( rows , Is . EqualTo ( expected ) ) ;
907
+ Assert . That ( rows1 , Is . EqualTo ( expected1 ) ) ;
908
+
909
+ // Same, but use column aliases for some columns from TableB whose names would conflict otherwise
910
+
911
+ var q2 = db . From < TableA > ( )
912
+ . Join < TableB > ( )
913
+ . Select < TableA , TableB > ( ( a , b ) => new { a , TableBId = b . Id , TableBName = b . Name } ) ;
914
+
915
+ var rows2 = db . Select < JoinSelectResults2 > ( q2 ) . OrderBy ( r => r . Id ) . ThenBy ( r => r . TableBId ) ;
916
+ var expected2 = new [ ]
917
+ {
918
+ new JoinSelectResults2 { Id = 1 , Bool = false , Name = "NameA1" , TableBId = 1 , TableBName = "NameB1" } ,
919
+ new JoinSelectResults2 { Id = 2 , Bool = true , Name = "NameA2" , TableBId = 2 , TableBName = "NameB2" } ,
920
+ new JoinSelectResults2 { Id = 2 , Bool = true , Name = "NameA2" , TableBId = 3 , TableBName = "NameB3" } ,
921
+ } ;
922
+ Assert . That ( rows2 , Is . EqualTo ( expected2 ) ) ;
888
923
}
889
924
finally
890
925
{
0 commit comments