Ejemplo n.º 1
0
        /// <summary>
        /// 获取绑定到当前线程的<see cref="ThreadLocalTransactionKeeper"/>实例。
        /// </summary>
        /// <param name="dbProviderFactory"><see cref="DbProviderFactory"/>实例。</param>
        /// <param name="connectionString">初始化数据库连接的连接字符串。</param>
        /// <returns><see cref="ThreadLocalTransactionKeeper"/>实例。</returns>
        public static ThreadLocalTransactionKeeper OpenTransaction(
            DbProviderFactory dbProviderFactory, string connectionString)
        {
            var theadId = Thread.CurrentThread.ManagedThreadId;
            ThreadLocalTransactionKeeper keeper;

            lock (Keepers)
            {
                if (Keepers.TryGetValue(theadId, out keeper))
                {
                    keeper._embeddedLevel++;
                }
                else
                {
                    keeper = new ThreadLocalTransactionKeeper(dbProviderFactory, connectionString);
                    Keepers.Add(theadId, keeper);
                }
            }

            return(keeper);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 创建事务容器。
 /// </summary>
 /// <returns><see cref="ITransactionKeeper"/>。</returns>
 public virtual ITransactionKeeper CreateTransaction()
 {
     return(ThreadLocalTransactionKeeper.OpenTransaction(Factory, ConnectionString));
 }