コード例 #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);
 }
コード例 #2
0
        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());
        }
コード例 #3
0
        public async Task <T> AddAsync(T entity)
        {
            await _moviesContext.Set <T>().AddAsync(entity);

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