当前位置: 首页>>代码示例>>C#>>正文


C# Npgsql.NpgsqlTransaction类代码示例

本文整理汇总了C#中Npgsql.NpgsqlTransaction的典型用法代码示例。如果您正苦于以下问题:C# NpgsqlTransaction类的具体用法?C# NpgsqlTransaction怎么用?C# NpgsqlTransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NpgsqlTransaction类属于Npgsql命名空间,在下文中一共展示了NpgsqlTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ForTransactionalWork

        /// <summary>
        /// Constructs a <see cref="ConnectionHolder"/> instance with the given connection and transaction. The connection
        /// will be used for transactional work
        /// </summary>
        public static ConnectionHolder ForTransactionalWork(NpgsqlConnection connection, NpgsqlTransaction transaction)
        {
            if (connection == null) throw new ArgumentNullException("connection");
            if (transaction == null) throw new ArgumentNullException("transaction");

            return new ConnectionHolder(connection, transaction);
        }
开发者ID:JanRou,项目名称:Rebus,代码行数:11,代码来源:ConnectionHolder.cs

示例2: Delete

 public static int Delete(IEnumerable<int> malAnimeIds, NpgsqlConnection conn, NpgsqlTransaction transaction)
 {
     string idList = string.Join(", ", malAnimeIds.Select(id => id.ToString(CultureInfo.InvariantCulture)));
     string deleteSql = string.Format("DELETE FROM mal_anime_synonym WHERE mal_anime_id IN ({0})", idList);
     int numRowsDeleted = conn.Execute(deleteSql, transaction: transaction);
     return numRowsDeleted;
 }
开发者ID:mageomageos,项目名称:animerecs,代码行数:7,代码来源:mal_anime_synonym.cs

示例3: Init

        private void Init(PostgresProcessor processor, IEnumerable<string> columnDefinitions)
        {
            Connection = (NpgsqlConnection)processor.Connection;
            Transaction = (NpgsqlTransaction)processor.Transaction;

            NameWithSchema = string.IsNullOrEmpty(_schemaName) ? Name : string.Format("\"{0}\".{1}", _schemaName, Name);
            Create(columnDefinitions);
        }
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:8,代码来源:PostgresTestTable.cs

示例4: ExecuteNonQuery

        public static int ExecuteNonQuery(NpgsqlTransaction transaction, CommandType commandType, string commandText, params NpgsqlParameter[] commandParameters)
        {
            if (transaction == null) { throw new ArgumentNullException("transaction"); }
            if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");

            NpgsqlCommand command = new NpgsqlCommand();
            PrepareCommand(command, transaction.Connection, transaction, commandType, commandText, commandParameters);
            return command.ExecuteNonQuery();
        }
开发者ID:saiesh86,项目名称:TravelBlog,代码行数:9,代码来源:NpgsqlHelper.cs

示例5: PostgresTestSequence

        public PostgresTestSequence(PostgresProcessor processor, string schemaName, string sequenceName)
        {
            _schemaName = schemaName;
            Name = quoter.QuoteSequenceName(sequenceName);

            Connection = (NpgsqlConnection)processor.Connection;
            Transaction = (NpgsqlTransaction)processor.Transaction;
            NameWithSchema = string.IsNullOrEmpty(_schemaName) ? Name : string.Format("\"{0}\".{1}", _schemaName, Name);
            Create();
        }
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:10,代码来源:PostgresTestSequence.cs

示例6: AsDataSource

        /// <summary>
        /// Returns a data source wrapped around the transaction.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="transaction">The transaction.</param>
        /// <returns>SqlServerOpenDataSource.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static PostgreSqlOpenDataSource AsDataSource(this NpgsqlConnection connection, NpgsqlTransaction transaction)
        {
            if (connection == null)
                throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null.");
            if (connection.State == ConnectionState.Closed)
                connection.Open();

            var dataSourceBase = s_CachedDataSources.GetOrAdd(connection.ConnectionString, cs => new PostgreSqlDataSource(cs));
            return new PostgreSqlOpenDataSource(dataSourceBase, connection, transaction);
        }
开发者ID:docevaad,项目名称:Chain,代码行数:17,代码来源:PostgreSqlExtensions.cs

示例7: SetJobLastKnownEventCommand

 /// <summary>
 /// Initializes a new instance of the <see cref="SetJobLastKnownEventCommand" /> class.
 /// </summary>
 /// <param name="jobName">Name of the job.</param>
 /// <param name="jobEventTime">The time.</param>
 /// <param name="jobScheduledTime">The job scheduled time.</param>
 /// <param name="connection">The connection.</param>
 /// <param name="transaction">The transaction.</param>
 public SetJobLastKnownEventCommand(string jobName,
     DateTimeOffset jobEventTime,
     DateTimeOffset jobScheduledTime,
     NpgsqlConnection connection,
     NpgsqlTransaction transaction)
 {
     JobName = jobName;
     JobEventTime = jobEventTime;
     JobScheduledTime = jobScheduledTime;
     Connection = connection;
     Transaction = transaction;
 }
开发者ID:blehnen,项目名称:DotNetWorkQueue,代码行数:20,代码来源:SetJobLastKnownEventCommand.cs

示例8: DeleteOldestUsers

        public static void DeleteOldestUsers(long numUsers, NpgsqlConnection conn, NpgsqlTransaction transaction)
        {
            if (numUsers == 0)
            {
                return;
            }
            if (numUsers < 0)
            {
                throw new ArgumentOutOfRangeException("numUsers", numUsers, string.Format("Cannot delete {0} oldest users", numUsers));
            }

            string deleteSql = @"DELETE FROM mal_user WHERE mal_user_id IN
            (SELECT mal_user_id FROM mal_user
            ORDER BY time_added
            LIMIT :NumToDelete)";

            conn.Execute(deleteSql, new { NumToDelete = numUsers }, transaction);
        }
开发者ID:mageomageos,项目名称:animerecs,代码行数:18,代码来源:mal_user.cs

示例9: Insert

        public static int Insert(IEnumerable<mal_anime_synonym> synonyms, NpgsqlConnection conn, NpgsqlTransaction transaction)
        {
            StringBuilder sqlBuilder = new StringBuilder("INSERT INTO mal_anime_synonym (mal_anime_id, synonym) VALUES ");

            bool anyRows = false;
            using (NpgsqlCommand cmd = new NpgsqlCommand())
            {
                int numSynonym = 1;
                foreach (var synIter in synonyms.AsSmartEnumerable())
                {
                    mal_anime_synonym synonym = synIter.Value;
                    if (!synIter.IsFirst)
                    {
                        sqlBuilder.AppendLine(", ");
                    }
                    sqlBuilder.AppendFormat("(:MalAnimeId{0}, :Synonym{0})", numSynonym);

                    cmd.Parameters.AddWithValue(string.Format("MalAnimeId{0}", numSynonym), synonym.mal_anime_id);
                    cmd.Parameters.AddWithValue(string.Format("Synonym{0}", numSynonym), synonym.synonym);

                    numSynonym++;
                    anyRows = true;
                }

                if (anyRows)
                {
                    cmd.Connection = conn;
                    cmd.Transaction = transaction;
                    cmd.CommandText = sqlBuilder.ToString();
                    int numRowsInserted = cmd.ExecuteNonQuery();
                    return numRowsInserted;
                }
                else
                {
                    return 0;
                }
            }
        }
开发者ID:mageomageos,项目名称:animerecs,代码行数:38,代码来源:mal_anime_synonym.cs

示例10: Enlist

 public void Enlist(Transaction tx)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Enlist");
     if (tx != null)
     {
         _isolationLevel = tx.IsolationLevel;
         if (!tx.EnlistPromotableSinglePhase(this))
         {
             // must already have a durable resource
             // start transaction
             _npgsqlTx = _connection.BeginTransaction(ConvertIsolationLevel(_isolationLevel));
             _inTransaction = true;
             _rm = CreateResourceManager();
             _callbacks = new NpgsqlTransactionCallbacks(_connection);
             _rm.Enlist(_callbacks, TransactionInterop.GetTransmitterPropagationToken(tx));
             // enlisted in distributed transaction
             // disconnect and cleanup local transaction
             _npgsqlTx.Cancel();
             _npgsqlTx.Dispose();
             _npgsqlTx = null;
         }
     }
 }
开发者ID:callixte,项目名称:Npgsql2,代码行数:23,代码来源:NpgsqlPromotableSinglePhaseNotification.cs

示例11: GetTableNames

        public static List<string> GetTableNames(this NpgsqlConnection connection, NpgsqlTransaction transaction = null)
        {
            var tableNames = new List<string>();

            using (var command = connection.CreateCommand())
            {
                if (transaction != null)
                {
                    command.Transaction = transaction;
                }

                command.CommandText = "select * from information_schema.tables where table_schema not in ('pg_catalog', 'information_schema')";

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tableNames.Add(reader["table_name"].ToString());
                    }
                }
            }

            return tableNames;
        }
开发者ID:JanRou,项目名称:Rebus,代码行数:24,代码来源:PostgreSqlMagic.cs

示例12: ExecuteScalarAsync

 protected async Task<object> ExecuteScalarAsync(string sql, NpgsqlConnection conn = null, NpgsqlTransaction tx = null)
 {
     if (conn == null)
         conn = Conn;
     var cmd = tx == null ? new NpgsqlCommand(sql, conn) : new NpgsqlCommand(sql, conn, tx);
     using (cmd)
         return await cmd.ExecuteScalarAsync();
 }
开发者ID:Emill,项目名称:Npgsql,代码行数:8,代码来源:TestBase.cs

示例13: commitTransaction

 public void commitTransaction()
 {
     if ((con != null) && (trans != null) && (con.State == System.Data.ConnectionState.Open))
     {
         trans.Commit();
         trans = null;
     }
 }
开发者ID:4nub1s,项目名称:infoGym,代码行数:8,代码来源:Banco.cs

示例14: PostgreSqlTransaction

        public PostgreSqlTransaction(NpgsqlConnection connection)
        {
            if (connection.State != ConnectionState.Open)
            {
                connection.Open();
            }

            _transaction = connection.BeginTransaction(IsolationLevel.Serializable);
        }
开发者ID:mantasaudickas,项目名称:database-migrator,代码行数:9,代码来源:PostgreSqlTransaction.cs

示例15: BeginTransaction

        void BeginTransaction()
        {
            if (currentTransaction != null)
            {
                throw new InvalidOperationException("Cannot begin new transaction when a transaction has already been started!");
            }

            currentTransaction = GetOrCreateConnection().Connection.BeginTransaction();
        }
开发者ID:JanRou,项目名称:Rebus,代码行数:9,代码来源:TestPostgreSqlSubscriptionStorage_UserProvidedConnection.cs


注:本文中的Npgsql.NpgsqlTransaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。