コード例 #1
0
        public async Task <TReturn> Execute <TReturn>(ISqlQuery <TReturn> sqlQuery, SqlExecutionContext context = null)
        {
            if (context != null)
            {
                return(await sqlQuery.Execute(context.Connection, context.Transaction));
            }

            return(await _executionStrategy.Value.ExecuteAsync(
                       async() =>
            {
                using (var connection = _connectionFactory.Value.Invoke())
                {
                    await connection.Value.OpenAsync();

                    var dbTransaction = connection.Value.BeginTransaction();

                    try
                    {
                        var result = await sqlQuery.Execute(connection.Value, dbTransaction);

                        dbTransaction.Commit();

                        return result;
                    }
                    finally
                    {
                        dbTransaction.Dispose();
                    }
                }
            }));
        }
コード例 #2
0
        public async Task Execute(ISqlCommand sqlCommand, SqlExecutionContext context = null)
        {
            if (context != null)
            {
                await sqlCommand.Execute(context.Connection, context.Transaction);

                return;
            }

            await _executionStrategy.Value.ExecuteAsync(
                async() =>
            {
                using (var connection = _connectionFactory.Value.Invoke())
                {
                    await connection.Value.OpenAsync();

                    var dbTransaction = connection.Value.BeginTransaction();

                    try
                    {
                        await sqlCommand.Execute(connection.Value, dbTransaction);

                        dbTransaction.Commit();
                    }
                    finally
                    {
                        dbTransaction.Dispose();
                    }
                }
            });
        }