Exemplo n.º 1
0
        /// <summary>
        /// 初始化 <see cref="EntityTransactionScope"/> 类的新实例。
        /// </summary>
        /// <param name="option">选项。</param>
        public EntityTransactionScope(EntityTransactionScopeOption option = null)
        {
            var database = DatabaseFactory.GetDatabaseFromScope();

            if (database != null)
            {
                SetDatabase(DatabaseScope.Current.InstanceName, database);
                EntityDatabaseFactory.StartTransaction(database, option);
            }

            Option = option;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 启动数据库事务。
        /// </summary>
        /// <param name="database"></param>
        /// <param name="option"></param>
        public static void StartTransaction(IDatabase database, EntityTransactionScopeOption option)
        {
            var isolationLevel = IsolationLevel.ReadCommitted;

            if (option != null)
            {
                //设置超时时间
                if (option.Timeout != TimeSpan.Zero)
                {
                    database.Timeout = (int)option.Timeout.TotalSeconds;
                }

                isolationLevel = option.IsolationLevel;
            }

            database.BeginTransaction(isolationLevel);
        }
 /// <summary>
 /// 初始化 <see cref="EntityTransactionScope"/> 类的新实例。
 /// </summary>
 /// <param name="option">选项。</param>
 public EntityTransactionScope(EntityTransactionScopeOption option = null)
 {
     Option = option ?? new EntityTransactionScopeOption {
         IsolationLevel = System.Data.IsolationLevel.ReadCommitted
     };
 }