public List <Car> GetAll(Expression <Func <Car, bool> > filter = null) { using (CarContext context = new CarContext()) { return(filter == null ? context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList()); } }
public Car Get(Expression <Func <Car, bool> > filter) { using (CarContext context = new CarContext()) { return(context.Set <Car>().SingleOrDefault(filter)); } }
public TEntity Add(TEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } _context.Set <TEntity>().Add(entity); return(entity); }
/// <summary> /// Gets all entity records with included entities /// </summary> /// <param name="includes">included entities</param> /// <returns>IQueryable of all entity records with included entities, if includes is null this function is equal GetAll</returns> public IQueryable <TEntity> Query(params Expression <Func <TEntity, object> >[] includes) { DbSet <TEntity> dbSet = context.Set <TEntity>(); IQueryable <TEntity> query = dbSet; foreach (var include in includes) { query = query.Include(include); } return(query ?? dbSet); }
public GenericRepositiory(CarContext context) { _context = context; _dbSet = context.Set <T>(); }
public Repository(CarContext _context) { context = _context; dbEntities = context.Set <TEntity>(); }
/// <summary> /// IQueryable延迟加载集合,调用时才会去加载至内存 /// List查询后会立即加载至内存中 /// </summary> /// <returns></returns> public IQueryable <T> GetEntitys(Expression <Func <T, bool> > lambdaWhere) { //context.UserInfoes.Where(lambdaWhere); return(context.Set <T>().Where(lambdaWhere)); }