Пример #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);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// 返回一个Batch
 /// </summary>
 /// <returns></returns>
 public DbBatch BeginBatch()
 {
     return(dbTrans.BeginBatch());
 }