Using ToListAsync() with Automapper ProjectToQueryable()

automapper c# entity-framework entity-framework-6

Accepted Answer

Here is how I changed my approach to be async for anybody reading this question:

return await GetDbContext().Items
              .ProjectTo<DTO>(automapperConfigProvider)
              .Where()
              .Decompil‌​eAsync()
              .OrderBy().ThenBy(...)
              .Skip(skip).Take(take) 
              .ToListAsync();

In essence, I wanted the data server to handle all of the effort involved in projecting the dataset to DTO, running the query, and then selecting only a portion of the results based on paging information.

I looked into theUseAsDataSource() alternative that Jimmy Bogard brought up in his response to Darcy's response. However, I was use an AutoMapper.Profile I used it as a configuration provider for my mapping, but I was unable to convert it to anIMapper passing toUseAsDataSource() . Thus, I decided against following Jimmy's advice.

There may be more approaches to solving this, but the code above worked for me.

1
8/26/2016 12:46:14 PM

Popular Answer

This becauseProjectToQueryable<T> lacks implementationIDbAsyncEnumerable .

There is, however, an async equivalent..ProjectToListAsync<T>(); in the package AutoMapper.EF6.

Zzz-26-Zzz for further information.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow