I have repository method which returns collection according to filter
public IEnumerable<T> GetMany(Expression<Func<T, bool>> filter = null)
{
IQueryable<T> query = DbSet;
if (filter != null)
{
query = query.Where(filter);
}
return query.ToList();
}
Now I want to write this method as Async. And this is my problem.
Should I change type of DbSet (DbSet<T>
) to something else or what is the correct solution?
protected readonly DbSet<T> DbSet;
public Repository(AdminDbContext context)
{
this.Context = context;
this.DbSet = context.Set<T>();
}
UPD : return query.ToListAsync();
- is it enough ? Thanks
As specified in this MSDN article, you still use
DbSet
, but you use async extensions for accessing the set.Here's an async version of your code: