Example #1
0
        /// <param name = "isolationLevel">
        ///     Only SQL standard isolation levels are supported, except
        ///     <see cref = "IsolationLevel.Snapshot" />.
        /// </param>
        /// <exception cref = "SqlException" />
        /// <exception cref = "OperationCanceledException" />
        public static ValueTask SetIsolationLevel
            (this ISqlTransaction transaction, IsolationLevel isolationLevel, CancellationToken ct = default)
        {
            var sql =
                isolationLevel switch {
                IsolationLevel.ReadUncommitted => setReadUncommittedSql,
                IsolationLevel.ReadCommitted => setReadCommittedSql,
                IsolationLevel.RepeatableRead => setRepeatableReadSql,
                IsolationLevel.Serializable => setSerializableSql,
                IsolationLevel.Unspecified =>
                throw new ArgumentException(
                          "Transaction has no specified isolation level.",
                          nameof(transaction)),
                      IsolationLevel.Snapshot =>
                      throw new ArgumentException(
                                "Snapshot isolation level cannot be set by this method.",
                                nameof(transaction)),
                            _ =>
                            throw new ArgumentException(
                                      $"Isolation level {isolationLevel} is not part of SQL standard.",
                                      nameof(transaction))
            };

            return(transaction.ExecuteAsync(sql, ct));
        }
    }
Example #2
0
        /// <exception cref = "SqlException" />
        /// <exception cref = "OperationCanceledException" />
        public static ValueTask SetAccessAsync
            (this ISqlTransaction transaction, SqlAccess access, CancellationToken ct = default)
        {
            var sql = access switch { SqlAccess.Rw => setRwSql, SqlAccess.Ro => setRoSql };

            return(transaction.ExecuteAsync(sql, ct));
        }

        const String setReadUncommittedSql = "set transaction isolation level read uncommitted";
Example #3
0
 /// <exception cref = "SqlException" />
 /// <exception cref = "OperationCanceledException" />
 public static ValueTask SetRoAsync
     (this ISqlTransaction transaction, CancellationToken cancellationToken = default) =>
 transaction.ExecuteAsync(setRoSql, cancellationToken);
Example #4
0
 /// <exception cref = "SqlException" />
 /// <exception cref = "OperationCanceledException" />
 public static ValueTask SetSerializable(this ISqlTransaction transaction, CancellationToken ct = default) =>
 transaction.ExecuteAsync(setSerializableSql, ct);
Example #5
0
 /// <exception cref = "SqlException" />
 /// <exception cref = "OperationCanceledException" />
 public static ValueTask SetRepeatableRead(this ISqlTransaction transaction, CancellationToken ct = default) =>
 transaction.ExecuteAsync(setRepeatableReadSql, ct);