public void Delete(System.Linq.Expressions.Expression <Func <T, bool> > query) { foreach (var item in _dbSet.Where(query)) { Delete(item); } }
public List <T> GetAll(System.Linq.Expressions.Expression <Func <T, bool> > filter) { return(dbSet.Where(filter).ToList()); }
public virtual IEnumerable <TEntity> GetMany(Func <TEntity, bool> where) { return(_entitySet.Where(where).ToList()); }
public virtual List <T> QueryWhere(Expression <Func <T, bool> > where) { return(_dbset.Where(where).ToList()); }
/// <summary> /// 2.1 根据条件删除 /// </summary> /// <param name="delWhere"></param> /// <returns>返回受影响的行数</returns> public int DelBy(Expression <Func <TEntity, bool> > delWhere) { //2.1.1 查询要删除的数据 List <TEntity> listDeleting = entities.Where(delWhere).ToList(); //2.1.2 将要删除的数据 用删除方法添加到 EF 容器中 listDeleting.ForEach(u => { entities.Attach(u); //先附加到EF 容器 entities.Remove(u); //标识为删除状态 }); //2.1.3 一次性生成sql语句 到数据库执行删除 return(dbContext.SaveChanges()); }