public DataBaseRepository(MyBlogContext dbContext)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException("dbContext can not be null.");
            }

            _dbContext = dbContext;
            _dbSet     = dbContext.Set <T>();
        }
 public async Task <List <TEntity> > GetAllAsync()
 {
     return(await _context.Set <TEntity>().ToListAsync());
 }
Beispiel #3
0
 public async Task <TEntity> GetAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new MyBlogContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(filter));
 }
Beispiel #4
0
 public async Task <List <TEntity> > GetAllAsync <TKey>(Expression <Func <TEntity, TKey> > keySelector)
 {
     using var context = new MyBlogContext();
     return(await context.Set <TEntity>().OrderByDescending(keySelector).ToListAsync());
 }
Beispiel #5
0
 public async Task <List <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new MyBlogContext();
     return(await context.Set <TEntity>().Where(filter).ToListAsync());
 }
Beispiel #6
0
 public async Task <List <TEntity> > GetAllAsync()
 {
     using var context = new MyBlogContext();
     return(await context.Set <TEntity>().ToListAsync());
 }