Exemple #1
0
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="entityList"></param>
        /// <returns></returns>
        public virtual bool BatchUpdate_Entitys(List <T> entityList)
        {
            //使用事务进行批量数据更新
            using (DbTrans trans = db.BeginTrans())
            {
                try
                {
                    DbBatch batch = trans.BeginBatch(entityList.Count);
                    entityList.ForEach(item =>
                    {
                        item.Attach();
                        batch.Save(item);
                    });
                    batch.Process();

                    trans.Commit();
                    return(true);
                }
                catch
                {
                    trans.Rollback();
                    return(false);
                }
            }
        }
Exemple #2
0
 internal DbTrans(DbProvider dbProvider, IsolationLevel isolationLevel)
 {
     this.dbConnection = dbProvider.CreateConnection();
     this.dbConnection.Open();
     this.dbTransaction = dbConnection.BeginTransaction(isolationLevel);
     this.dbProvider    = dbProvider;
     this.dbBatch       = new DbBatch(dbProvider, this);
 }
Exemple #3
0
 /// <summary>
 /// 以BbConnection方式实例化一个事务
 /// </summary>
 /// <param name="dbProvider"></param>
 /// <param name="dbConnection"></param>
 internal DbTrans(DbProvider dbProvider, DbConnection dbConnection)
 {
     this.dbConnection = dbConnection;
     if (this.dbConnection.State != ConnectionState.Open)
     {
         this.dbConnection.Open();
     }
     this.dbProvider = dbProvider;
     this.dbBatch    = new DbBatch(dbProvider, this);
 }
Exemple #4
0
 internal DbTrans(DbProvider dbProvider, bool useTrans)
 {
     if (useTrans)
     {
         this.dbConnection = dbProvider.CreateConnection();
         this.dbConnection.Open();
         this.dbTransaction = dbConnection.BeginTransaction();
     }
     this.dbProvider = dbProvider;
     this.dbBatch    = new DbBatch(dbProvider, this);
 }