@@ -35,6 +35,45 @@ public void BasicSelectEnumerable()
35
35
Assert . Equal ( "SELECT \" id\" , \" name\" FROM \" users\" " , c [ EngineCodes . Oracle ] ) ;
36
36
}
37
37
38
+ [ Fact ]
39
+ public void SelectAsOneColumn ( )
40
+ {
41
+ var query = new Query ( ) . SelectAs ( "Row" , "Alias" ) . From ( "Table" ) ;
42
+
43
+ var c = Compile ( query ) ;
44
+ Assert . Equal ( "SELECT [Row] AS [Alias] FROM [Table]" , c [ EngineCodes . SqlServer ] ) ;
45
+ Assert . Equal ( "SELECT `Row` AS `Alias` FROM `Table`" , c [ EngineCodes . MySql ] ) ;
46
+ Assert . Equal ( "SELECT \" Row\" AS \" Alias\" FROM \" Table\" " , c [ EngineCodes . PostgreSql ] ) ;
47
+ Assert . Equal ( "SELECT \" ROW\" AS \" ALIAS\" FROM \" TABLE\" " , c [ EngineCodes . Firebird ] ) ;
48
+ Assert . Equal ( "SELECT \" Row\" \" Alias\" FROM \" Table\" " , c [ EngineCodes . Oracle ] ) ;
49
+ }
50
+
51
+ [ Fact ]
52
+ public void SelectAsSingletonList ( )
53
+ {
54
+ var query = new Query ( ) . SelectAs ( ( "Row" , "Alias" ) ) . From ( "Table" ) ;
55
+
56
+ var c = Compile ( query ) ;
57
+ Assert . Equal ( "SELECT [Row] AS [Alias] FROM [Table]" , c [ EngineCodes . SqlServer ] ) ;
58
+ Assert . Equal ( "SELECT `Row` AS `Alias` FROM `Table`" , c [ EngineCodes . MySql ] ) ;
59
+ Assert . Equal ( "SELECT \" Row\" AS \" Alias\" FROM \" Table\" " , c [ EngineCodes . PostgreSql ] ) ;
60
+ Assert . Equal ( "SELECT \" ROW\" AS \" ALIAS\" FROM \" TABLE\" " , c [ EngineCodes . Firebird ] ) ;
61
+ Assert . Equal ( "SELECT \" Row\" \" Alias\" FROM \" Table\" " , c [ EngineCodes . Oracle ] ) ;
62
+ }
63
+
64
+ [ Fact ]
65
+ public void SelectAsMultipleColumns ( )
66
+ {
67
+ var query = new Query ( ) . SelectAs ( ( "Row1" , "Alias1" ) , ( "Row2" , "Alias2" ) ) . From ( "Table" ) ;
68
+
69
+ var c = Compile ( query ) ;
70
+ Assert . Equal ( "SELECT [Row1] AS [Alias1], [Row2] AS [Alias2] FROM [Table]" , c [ EngineCodes . SqlServer ] ) ;
71
+ Assert . Equal ( "SELECT `Row1` AS `Alias1`, `Row2` AS `Alias2` FROM `Table`" , c [ EngineCodes . MySql ] ) ;
72
+ Assert . Equal ( "SELECT \" Row1\" AS \" Alias1\" , \" Row2\" AS \" Alias2\" FROM \" Table\" " , c [ EngineCodes . PostgreSql ] ) ;
73
+ Assert . Equal ( "SELECT \" ROW1\" AS \" ALIAS1\" , \" ROW2\" AS \" ALIAS2\" FROM \" TABLE\" " , c [ EngineCodes . Firebird ] ) ;
74
+ Assert . Equal ( "SELECT \" Row1\" \" Alias1\" , \" Row2\" \" Alias2\" FROM \" Table\" " , c [ EngineCodes . Oracle ] ) ;
75
+ }
76
+
38
77
[ Fact ]
39
78
public void BasicSelectWhereBindingIsEmptyOrNull ( )
40
79
{
@@ -74,6 +113,21 @@ public void ExpandedSelect()
74
113
Assert . Equal ( "SELECT `users`.`id`, `users`.`name`, `users`.`age` FROM `users`" , c [ EngineCodes . MySql ] ) ;
75
114
}
76
115
116
+ [ Fact ]
117
+ public void ExpandedSelectAs ( )
118
+ {
119
+ var q = new Query ( ) . From ( "users" ) . SelectAs ( ( "users.{id,name, age}" , "Alias" ) ) ;
120
+ var c = Compile ( q ) ;
121
+
122
+ // This result is weird (but valid syntax), and at least it works in
123
+ // a somewhat explainable way, as opposed to regular Select() when
124
+ // combining the expanded syntax and the 'as' SQLKata keyword support
125
+ // which simply silently stops working when the {...} expansion is
126
+ // applied.
127
+ Assert . Equal ( "SELECT [users].[id] AS [Alias], [users].[name] AS [Alias], [users].[age] AS [Alias] FROM [users]" , c [ EngineCodes . SqlServer ] ) ;
128
+ Assert . Equal ( "SELECT `users`.`id` AS `Alias`, `users`.`name` AS `Alias`, `users`.`age` AS `Alias` FROM `users`" , c [ EngineCodes . MySql ] ) ;
129
+ }
130
+
77
131
[ Fact ]
78
132
public void ExpandedSelectWithSchema ( )
79
133
{
0 commit comments