/// <summary> /// 根据条件删除实体 /// </summary> /// <param name="where">lambda表达式</param> /// <param name="autoSave"></param> public void Delete(Expression <Func <TEntity, bool> > where, bool autoSave = true) { _dbSet.Where(where).ToList().ForEach(it => _dbContext.Set <TEntity>().Remove(it)); if (autoSave) { Save(); } }
/// <summary> /// 通过构造函数注入得到数据上下文对象实例 /// </summary> /// <param name="dbContext"></param> public RepositoryBase(MyWebSiteDbContext dbContext) { _dbContext = dbContext; _dbSet = dbContext.Set <TEntity>(); }