當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。