4 Answer(s)
-
0
Because it's impossible. First of all, only EF supports Async. So, async is not general. Second; IQueryable does not support async and it can not support. Async is used at the end (while executing the query), for example you can use GetAll().Where(...).ToListAsync(); So, ToList method has async version as ToListAsync. As similar, there is a FirstOrDefaultAsync and so on... You can use ToListAsync() if you add EntityFramework reference to your project.
-
0
I understood. I read the sources and others methods uses GetAll() but return Async, so works as expected.
Tks.
-
0
It would be enough to add support for projection for FirstOrDefaultAsync and GetAllListAsync. That should cover most of the scenarios. Overload would cause a problems, so designed the interface methods like this:
Task<TModel> QueryFirstOrDefaultAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection); Task<List<TModel>> QueryToListAsync<TModel>(Func<IQueryable<TEntity>, IQueryable<TModel>> projection);
Usage example:
var result = await _myRepo.QueryFirstOrDefaultAsync(q => q.Where(x => x.Id == id).ProjectTo<MyDto>());
or without using AutoMapper's IQuerable extension:
var result = await _myRepo.QueryFirstOrDefaultAsync(q => q.Where(x => x.Id == id).Select(x => x.Status));
Such implementation for EF repository is quite straightforward. Not sure about NHibernate.
What is your opinion on this?
PS: I can contribute if we agree on this solution. I am also opened to any suggestions how should final method names look like.
-
0
Hi,
Instead of adding methods to repository, we can add extension methods to IQueryable<T>. Because, other people will need to CountAsync, SingleAsync.. and so on. This can be good but I could not find a good naming yet. Because, if we name it as "ToListAsync" then it will conflict with EF's "ToListAsync" when we have EF reference.
Let's continue this discussion on Github. Can you create an issue for it by referencing this forum post? Thanks.