Ejemplo n.º 1
0
        /// <summary>
        /// 删除过期用户 在定时任务中调用
        /// </summary>
        public void DeleteExpireUser()
        {
            // 过期用户
            var expUsers = CurrentDal.GetEntities(p => p.Grade + p.LoSch < DateTime.Now.Year);

            if (expUsers.Count() == 0)
            {
                return;
            }

            // 相关填写记录
            var userIds = expUsers.Select(x => x.Id);
            var wtLogs  = DbSession.WtLogDal.GetEntities(p => userIds.Contains(p.User.Id));

            try
            {
                DbSession.WtLogDal.DeleteRange(wtLogs);
                DbSession.SaveChanges();
            }
            catch (Exception exception) { QssLogHelper.Log("批量删除填写记录失败", "在批量删除过期用户时,批量删除填写记录失败! 原因:" + exception.Message, QssLogType.Error, exception); }

            try
            {
                CurrentDal.DeleteRange(expUsers);
                DbSession.SaveChanges();
            }
            catch (Exception exception) { QssLogHelper.Log("批量删除过期用户失败", "在批量删除过期用户时,批量删除用户失败! 原因:" + exception.Message, QssLogType.Error, exception); }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除一系列实体
 /// 从基础化集的上下文中删除给定实体集合(每个实体都置于“已删除”状态),这样当调用 SaveChanges 时,会从数据库中删除它。
 /// </summary>
 /// <param name="entities">要删除的实体集合。</param>
 /// <returns></returns>
 public int DeleteRange(IEnumerable <T> entities)
 {
     CurrentDal.DeleteRange(entities);
     return(DbSession.SaveChanges());
 }