码迷,mamicode.com
首页 > 其他好文 > 详细

EF的增删改查

时间:2016-12-22 20:29:01      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:null   list   lag   false   guid   str   odi   adduser   根据id获取   

 //获取分组信息
        public List<UserGroupLogSys> GetUserGroupLogSyslist(int pageIndex, int pageSize, string userGroupFlag, string LogSys, string CompanyName, string MobileTemplate, out int count)
        {

            MainBCUnitOfWork currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
            int sum = (pageIndex - 1) * pageSize;
            List<UserGroupLogSys> list = currentUnitOfWork.UserGroupLogSys.Where(p => (string.IsNullOrEmpty(userGroupFlag) ? true : p.userGroupFlag.Contains(userGroupFlag)) && (string.IsNullOrEmpty(LogSys) ? true : p.LogSys.Contains(LogSys)) && (string.IsNullOrEmpty(CompanyName) ? true : p.CompanyName.Contains(CompanyName)) && (string.IsNullOrEmpty(MobileTemplate) ? true : p.MobileTemplate.Contains(MobileTemplate))).ToList();
            count = list.Count();
            list = list.Skip(sum).Take(pageSize).ToList();
            return list;
        }
        //添加分组
        public int AddUserGroupLog(UserGroupLogSys u)
        {
            MainBCUnitOfWork currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
            if (currentUnitOfWork.UserGroupLogSys.Where(p => p.userGroupFlag == u.userGroupFlag).Count() ==1)
            {
                return 0;
            }
            currentUnitOfWork.UserGroupLogSys.Add(u);
            return currentUnitOfWork.SaveChanges();
        }

        //根据ID删除分组
        public bool DeleteUserGroupLogByID(string ID)
        {
            MainBCUnitOfWork currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
            Guid id =new Guid(ID);
            UserGroupLogSys u = currentUnitOfWork.UserGroupLogSys.Single(ri => ri.ID == id);
            currentUnitOfWork.UserGroupLogSys.Remove(u);
            return currentUnitOfWork.SaveChanges() > 0 ? true : false;
        }
        //根据ID获取单条记录
        public UserGroupLogSys SearchUserGroupLogByID(Guid ID)
        {
          MainBCUnitOfWork currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
          return  currentUnitOfWork.UserGroupLogSys.Single(ri => ri.ID == ID);
        }
        //编辑信息
        public bool EditUserGroup(UserGroupLogSys u)
        {
            MainBCUnitOfWork currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
            currentUnitOfWork.Entry(u).State = System.Data.EntityState.Modified;
            return currentUnitOfWork.SaveChanges() > 0 ? true : false;
        }

EF的增删改查

标签:null   list   lag   false   guid   str   odi   adduser   根据id获取   

原文地址:http://www.cnblogs.com/dzdrmmf/p/6212278.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!