Ejemplo n.º 1
0
        public static async Task <TQueryResult> PocoQuery <TQueryResult>(this IDbConnectionCreator connectionCreator, Func <Database, Task <TQueryResult> > executeFunc)
        {
            using (var connection = connectionCreator.CreateDbConnection())
            {
                if (connection.State != ConnectionState.Open)
                {
                    await connection.OpenAsync();
                }

                using (var db = CreateDatabase(connection))
                {
                    try
                    {
                        return(await executeFunc(db).ConfigureAwait(false));
                    }
                    catch (SqlException ex)
                    {
                        connectionCreator.RaiseExecuteErrorEvent(ex);
                        throw;
                    }
                    finally
                    {
                        connectionCreator.RaiseCommandsExecutedEvent();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static TQueryResult PocoQuery <TQueryResult>(this IDbConnectionCreator connectionCreator, Func <Database, TQueryResult> executeFunc)
        {
            using (var connection = connectionCreator.CreateDbConnection())
            {
                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                }

                using (var db = CreateDatabase(connection))
                {
                    try
                    {
                        return(executeFunc(db));
                    }
                    catch (SqlException ex)
                    {
                        connectionCreator.RaiseExecuteErrorEvent(ex);
                        throw;
                    }
                    finally
                    {
                        connectionCreator.RaiseCommandsExecutedEvent();
                    }
                }
            }
        }