@@ -31,13 +31,14 @@ protected BulkInsertProviderBase(ILogger<BulkInsertProviderBase<TDialect>>? logg
3131 protected async Task < string > CreateTableCopyAsync < T > (
3232 bool sync ,
3333 DbContext context ,
34+ BulkInsertOptions options ,
3435 CancellationToken cancellationToken = default ) where T : class
3536 {
3637 var tableInfo = GetTableInfo ( context , typeof ( T ) ) ;
3738 var tableName = QuoteTableName ( tableInfo . SchemaName , tableInfo . TableName ) ;
3839 var tempTableName = QuoteTableName ( null , GetTempTableName ( tableInfo . TableName ) ) ;
3940
40- var keptColumns = string . Join ( ", " , GetQuotedColumns ( context , typeof ( T ) , false ) ) ;
41+ var keptColumns = string . Join ( ", " , GetQuotedColumns ( context , typeof ( T ) , options . CopyGeneratedColumns ) ) ;
4142 var query = string . Format ( CreateTableCopySql , tempTableName , tableName , keptColumns ) ;
4243
4344 await ExecuteAsync ( sync , context , query , cancellationToken ) ;
@@ -108,13 +109,21 @@ private async Task<List<TResult>> CopyFromTempTableWithoutKeysAsync<T, TResult>(
108109 {
109110 var ( schemaName , tableName , _) = GetTableInfo ( context , typeof ( T ) ) ;
110111 var quotedTableName = QuoteTableName ( schemaName , tableName ) ;
111-
112- var movedProperties = context . GetProperties ( typeof ( T ) , false ) ;
112+ var movedProperties = context . GetProperties ( typeof ( T ) , options . CopyGeneratedColumns ) ;
113113 var returnedProperties = returnData ? context . GetProperties ( typeof ( T ) ) : [ ] ;
114114
115115 var query = SqlDialect . BuildMoveDataSql < T > ( context , tempTableName , quotedTableName , movedProperties , returnedProperties , options , onConflict ) ;
116116
117117 if ( returnData )
118+ {
119+ return await QueryAsync ( sync , context , query , cancellationToken ) ;
120+ }
121+
122+ // If not returning data, just execute the command
123+ await ExecuteAsync ( sync , context , query , cancellationToken ) ;
124+ return [ ] ;
125+
126+ static async Task < List < TResult > > QueryAsync ( bool sync , DbContext context , string query , CancellationToken cancellationToken )
118127 {
119128 // Use EF to execute the query and return the results
120129 IQueryable < TResult > queryable = context
@@ -128,13 +137,9 @@ private async Task<List<TResult>> CopyFromTempTableWithoutKeysAsync<T, TResult>(
128137
129138 return await queryable . ToListAsync ( cancellationToken : cancellationToken ) ;
130139 }
131-
132- // If not returning data, just execute the command
133- await ExecuteAsync ( sync , context , query , cancellationToken ) ;
134- return [ ] ;
135140 }
136141
137- public async Task < List < T > > BulkInsertReturnEntities < T > (
142+ public virtual async Task < List < T > > BulkInsertReturnEntities < T > (
138143 bool sync ,
139144 DbContext context ,
140145 IEnumerable < T > entities ,
@@ -163,10 +168,12 @@ private static async Task Finish(bool sync, DbConnection connection, bool wasClo
163168 {
164169 // ReSharper disable once MethodHasAsyncOverloadWithCancellation
165170 transaction . Commit ( ) ;
171+ transaction . Dispose ( ) ;
166172 }
167173 else
168174 {
169175 await transaction . CommitAsync ( ctk ) ;
176+ await transaction . DisposeAsync ( ) ;
170177 }
171178 }
172179
@@ -184,7 +191,7 @@ private static async Task Finish(bool sync, DbConnection connection, bool wasClo
184191 }
185192 }
186193
187- public async Task BulkInsert < T > (
194+ public virtual async Task BulkInsert < T > (
188195 bool sync ,
189196 DbContext context ,
190197 IEnumerable < T > entities ,
@@ -225,11 +232,11 @@ public async Task BulkInsert<T>(
225232 var ( connection , wasClosed , transaction , wasBegan ) = await context . GetConnection ( sync , ctk ) ;
226233
227234 var tableName = tempTableRequired
228- ? await CreateTableCopyAsync < T > ( sync , context , ctk )
235+ ? await CreateTableCopyAsync < T > ( sync , context , options , ctk )
229236 : GetQuotedTableName ( context , typeof ( T ) ) ;
230237
231238 var properties = context
232- . GetProperties ( typeof ( T ) , false )
239+ . GetProperties ( typeof ( T ) , options . CopyGeneratedColumns )
233240 . Select ( p => new PropertyAccessor ( p ) )
234241 . ToArray ( ) ;
235242
0 commit comments