public virtual int Insert(IEnumerable <TEntity> entities, bool isSave = true) { try { _dbContext.Configuration.AutoDetectChangesEnabled = false; _dbContext.Set <TEntity>().AddRange(entities); return(isSave?_dbContext.SaveChanges():0); } finally { _dbContext.Configuration.AutoDetectChangesEnabled = true; } }
public int InsertData(int num) { Users entity = new Users(); entity.LoginName = Guid.NewGuid().ToString("N"); entity.Password = ""; entity.CreateTime = DateTime.Now; entity.UpdateTime = DateTime.Now; entity.Remark = num.ToString(); for (int i = 0; i < num; i++) { entity.Status = i % 2; model.Set <Users>().Add(entity); model.SaveChanges(); } return(num); }