/// <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); } } }
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); }
/// <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); }
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); }