示例#1
0
 public List <Car> GetAll(Expression <Func <Car, bool> > filter = null)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         return(filter == null?context.Set <Car>().ToList() : context.Set <Car>().Where(filter).ToList());
     }
 }
示例#2
0
 public List <Car> GetCarsByColorId(int id)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         return(context.Set <Car>().Where(p => p.ColorId == id).ToList());
     }
 }
示例#3
0
 public Car Get(Expression <Func <Car, bool> > filter)
 {
     using (CarRentalContext context = new CarRentalContext())
     {
         return(context.Set <Car>().SingleOrDefault(filter));
     }
 }
示例#4
0
        // public async Task Add(T entity)
        // {
        // //    return await _context.Set<T>().AddAsync(entity);
        //     await _context.AddAsync(entity);
        // }

        public async Task <IEnumerable <T> > Get()
        {
            var items = await _context.Set <T>().ToListAsync();

            return(items);
        }
示例#5
0
 public BaseRepository(CarRentalContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
示例#6
0
 public void Delete(TEntity entity)
 {
     _carRentalContext.Set <TEntity>().Remove(entity);
 }