Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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());
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public void BulkUpsert <T>(QueryParmContainer <T> query) where T : class
 {
     runAsyncMethod(() => BulkUpsertAsync(query));
 }