首页 > 代码库 > EF的增删改查
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的增删改查