示例#1
0
        public async Task <CompletableSynchronizedStorageSession> OpenSession(ContextBag contextBag)
        {
            var connection = await NpgSqlHelpers.NewConnection(_connectionString);

            var transaction = connection.BeginTransaction();

            return(new StorageSession(connection, transaction));
        }
        public async Task <CompletableSynchronizedStorageSession> TryAdapt(TransportTransaction transportTransaction, ContextBag context)
        {
            Transaction ambientTransaction;

            if (transportTransaction.TryGet(out ambientTransaction))
            {
                NpgsqlConnection existingSqlConnection;
                //SQL server transport in ambient TX mode
                if (transportTransaction.TryGet(out existingSqlConnection))
                {
                    return(new StorageSession(existingSqlConnection, null));
                }
                //Other transport in ambient TX mode
                var connection = await NpgSqlHelpers.NewConnection(_connectionString);

                return(new StorageSession(connection, connection.BeginTransaction()));
            }
            return(null);
        }