@@ -14,6 +14,7 @@ public class SQLQueryInsert<T> : ISQLQueryFragment, ISQLQuery, ISQLQueryWithOutp
14
14
private readonly List < string > _tableColumns ;
15
15
private readonly IDictionary < string , Expression > _insertParameters ;
16
16
private readonly IDictionary < string , object > _insertProperties ;
17
+ private readonly Expression [ ] _insertColumns ;
17
18
18
19
internal SQLQueryInsert ( IList < ISQLQueryFragment > fragments , SQLQuerySelect select )
19
20
{
@@ -73,6 +74,21 @@ internal SQLQueryInsert(IList<ISQLQueryFragment> fragments, Expression<Action<T>
73
74
AddSqlQueryInsertParameters ( ) ;
74
75
}
75
76
77
+ internal SQLQueryInsert ( IList < ISQLQueryFragment > fragments , SQLQuerySelect select , Expression < Func < T , object > > [ ] columns )
78
+ {
79
+ _fragments = fragments ;
80
+
81
+ _select = select ;
82
+
83
+ _insertColumns = columns ;
84
+
85
+ _tableColumns = GetTableColumns ( ) ;
86
+
87
+ _fragments . Add ( this ) ;
88
+
89
+ AddSqlQueryInsertSelect ( ) ;
90
+ }
91
+
76
92
public SQLQueryFragmentType FragmentType { get { return SQLQueryFragmentType . Insert ; } }
77
93
78
94
public SQLQueryOutput < TS > Output < TS > ( Expression < Func < T , TS > > output )
@@ -119,6 +135,10 @@ public string Translate(ISQLQueryTranslator expressionTranslator)
119
135
{
120
136
insertBuilder . Append ( $ "{ Environment . NewLine } ({ string . Join ( ", " , _tableColumns . Where ( c => _insertParameters . ContainsKey ( c ) ) . Select ( c => $ "[{ c } ]") ) } )") ;
121
137
}
138
+ else if ( _insertColumns != null )
139
+ {
140
+ insertBuilder . Append ( $ "{ Environment . NewLine } ({ string . Join ( ", " , _insertColumns . Select ( u => expressionTranslator . GetColumnsWithoutTableAlias ( expressionTranslator . Translate ( u , FragmentType ) ) ) ) } )") ;
141
+ }
122
142
else
123
143
{
124
144
insertBuilder . Append ( $ "{ Environment . NewLine } ({ string . Join ( ", " , _select . Select . Select ( u => expressionTranslator . GetColumnsWithoutTableAlias ( expressionTranslator . Translate ( u , FragmentType ) ) ) ) } )") ;
@@ -164,7 +184,7 @@ private List<string> GetTableColumns()
164
184
}
165
185
}
166
186
167
- public class SQLQueryInsertValues : ISQLQueryFragment
187
+ internal class SQLQueryInsertValues : ISQLQueryFragment
168
188
{
169
189
private readonly List < string > _tableColumns ;
170
190
private readonly IDictionary < string , object > _insertProperties ;
@@ -192,7 +212,7 @@ public string Translate(ISQLQueryTranslator expressionTranslator)
192
212
}
193
213
}
194
214
195
- public class SQLQueryInsertValuesFromSelect < T > : ISQLQueryFragment
215
+ internal class SQLQueryInsertValuesFromSelect < T > : ISQLQueryFragment
196
216
{
197
217
private readonly SQLQuerySelect _select ;
198
218
@@ -224,7 +244,7 @@ public string Translate(ISQLQueryTranslator expressionTranslator)
224
244
}
225
245
}
226
246
227
- public class SQLQueryInsertParameters < T > : ISQLQueryFragment
247
+ internal class SQLQueryInsertParameters < T > : ISQLQueryFragment
228
248
{
229
249
private readonly List < string > _tableColumns ;
230
250
private IDictionary < string , Expression > _insertParameters ;
0 commit comments