I've an application service method GetWithName
and I want to write async version of this. To do this I've tried to use ToListAsync()
but repository does not have this method.
public PagedResultDto<BookDto> GetWithName(SearchWithNameRequestDto input)
{
var books =
Repository
.Where(p => p.Name.Contains(input.Name))
.ToList();
return new PagedResultDto<BookDto>
{
TotalCount = books.Count,
Items = ObjectMapper.Map<List<Book>, List<BookDto>>(books)
};
}
How can I use async version of ToList
method?
ToListAsync
is ORM-dependent:
// using Microsoft.EntityFrameworkCore;
var query = Repository
.Where(p => p.Name.Contains(input.Name));
var books = await query.ToListAsync();
For a DI (ORM-independent) solution, inject IAsyncQueryableExecuter
and do:
// using Abp.Linq;
var query = Repository
.Where(p => p.Name.Contains(input.Name));
var books = await _asyncQueryableExecuter.ToListAsync(query);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.