EF的增删改查

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EF的增删改查相关的知识,希望对你有一定的参考价值。

 //获取分组信息
        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的增删改查的主要内容,如果未能解决你的问题,请参考以下文章

EF的增删改查

MySQL-增删改查简易操作

MySQL-增删改查简易操作

EF的增删改查(转载)

EF和ADO的增删改查方法总结

django配置模型增删改查