コード例 #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
        private static int ExecuteQuery(ISqlQuery queryToExecute)
        {
            int retVal = 0;

            try
            {
                retVal = queryToExecute.Execute();
                Console.WriteLine("Success");
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message + "\r\n\t" + queryToExecute.BuildSqlStatement());
            }

            return retVal;
        }