public async Task BulkUpsertAsync <T>(QueryParmContainer <T> query) where T : class { validateQueryParms(query, nameof(QueryParmContainer <T> .DataModels), nameof(QueryParmContainer <T> .PrimaryKeyColumns), nameof(QueryParmContainer <T> .PropertiesForJoin) ); await getConnectionAsync <T>(async connection => { using (var transaction = connection.BeginTransaction()) { try { await bulkCopyMergeAsync( query.DataModels, query.PropertiesForUpdate, query.PrimaryKeyColumns, query.PropertiesForJoin, connection, transaction, query.BatchSize).ConfigureAwait(false); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(null); }).ConfigureAwait(false); }
private void validateQueryParms <T>(QueryParmContainer <T> query, params string[] propertiesToValidate) { StringBuilder errorMessage = new StringBuilder(); foreach (string property in propertiesToValidate) { switch (property) { case nameof(QueryParmContainer <T> .DataModels): if (query.DataModels.IsNullOrEmpty()) { errorMessage.AppendLine("DataModels must be given"); } break; case nameof(QueryParmContainer <T> .PropertiesForUpdate): if (query.PropertiesForUpdate.IsNullOrEmpty()) { errorMessage.AppendLine("PropertiesForUpdate must be specified"); } break; case nameof(QueryParmContainer <T> .PrimaryKeyColumns): if (query.PrimaryKeyColumns.IsNullOrEmpty()) { errorMessage.AppendLine("PrimaryKeyColumns must be specified"); } break; case nameof(QueryParmContainer <T> .PropertiesForJoin): if (query.PropertiesForJoin.IsNullOrEmpty()) { errorMessage.AppendLine("PropertiesForJoin must be specified"); } break; } } if (errorMessage.Length > 0) { throw new NotSupportedException(errorMessage.ToString()); } }
public async Task BulkInsertAsync <T>(QueryParmContainer <T> query) where T : class { validateQueryParms(query, nameof(QueryParmContainer <T> .DataModels) ); await getConnectionAsync <T>(async connection => { using (var transaction = connection.BeginTransaction()) { try { await bulkCopyInsertAsync(query.DataModels, query.BatchSize, connection, transaction).ConfigureAwait(false); transaction.Commit(); } catch (Exception) { transaction.Rollback(); throw; } } return(null); }).ConfigureAwait(false); }
public void BulkUpsert <T>(QueryParmContainer <T> query) where T : class { runAsyncMethod(() => BulkUpsertAsync(query)); }