Exemplo n.º 1
0
 public MoviesContextBuilder AddEntities <TEntity>(params TEntity[] entities) where TEntity : class
 {
     foreach (var entity in entities)
     {
         _context.Set <TEntity>().Add(entity);
     }
     _context.SaveChanges();
     return(this);
 }
        public async Task <TEntity> GetBy(Expression <Func <TEntity, bool> > predicate, params Expression <Func <TEntity, object> >[] includeProperties)
        {
            IQueryable <TEntity> query = _dbContext.Set <TEntity>();

            foreach (var includeProperty in includeProperties)
            {
                query = query.Include(includeProperty);
            }

            return(await query.Where(predicate).FirstOrDefaultAsync());
        }
Exemplo n.º 3
0
        public async Task <T> AddAsync(T entity)
        {
            await _moviesContext.Set <T>().AddAsync(entity);

            return(await Task.FromResult(entity));
        }
Exemplo n.º 4
0
 public bool Exists(int id)
 {
     return(_context.Set <T>( )
            .Any(x => x.Id == id));
 }
Exemplo n.º 5
0
 public virtual async Task <T> GetByIdAsync(int id)
 {
     return(await _dbContext.Set <T>().FindAsync(id));
 }
Exemplo n.º 6
0
 public BaseRepository(MoviesContext context)
 {
     Context = context;
     DbSet   = context.Set <T>();
 }