The source IQueryable doesn't implement IDbAsyncEnumerable

May 29, 2014 at 3:53 PM
public async static Task<List<Book>> FindByTextAsync(this IRepositoryAsync<Book> repository, string text)
        {
            return await repository.FindByTextInternal(text).ToListAsync();
        }
        
        public static List<Book> FindByText(this IRepositoryAsync<Book> repository, string text) 
        {
            return repository.FindByTextInternal(text).ToList();
        }

        private static IQueryable<Book> FindByTextInternal(this IRepositoryAsync<Book> repository, string text)
        {
            IQueryObject<Book> query = new BookQuery()
                .OrElseTitleContains(text)
                .OrElseEditorContains(text)
                .OrElseLanguageContains(text)
                .OrElseMaterialContains(text);          

            return repository.Query(query).Select().AsQueryable();
        }
When I call:
var books = await _unitOfWork.RepositoryAsync<Book>().FindByTextAsync(keyWord);
I get:

The source IQueryable doesn't implement IDbAsyncEnumerable<LibraryEntityDataModel.Book>. Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations. For more details see http://go.microsoft.com/fwlink/?LinkId=287068._

Is there any way to make it work as expected?
Coordinator
Jun 3, 2014 at 7:19 PM
Create a custom method on your repository (https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Adding%20Custom%20Queries%20to%20Repository&referringTitle=Documentation), this will provide you EF's nativbe IQueryable before execution (binding), from here you should be able to return ToListAsync().
Jun 4, 2014 at 4:43 PM
Hi, lelong37!

lelong37 wrote:
Create a custom method on your repository (https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Adding%20Custom%20Queries%20to%20Repository&referringTitle=Documentation) (...)
As far as I understand, I have already added a custom query to the repository...
public async static Task<List<Book>> FindByTextAsync(this IRepositoryAsync<Book> repository, string text)
{
   return await repository.FindByTextInternal(text).ToListAsync();
}
lelong37 wrote:
this will provide you EF's nativbe IQueryable before execution (binding), from here you should be able to return ToListAsync().
This sounds great, but I'm striving to grasp how I should exactly implement your piece of advice. :-(
Would you be so kind as to give me a boost?

Thanks in advance,

EM
Coordinator
Jul 3, 2014 at 5:58 PM
Edited Jul 3, 2014 at 6:00 PM
You will need the IQueryable from EF before SQL plan has executed.

As documented here: https://genericunitofworkandrepositories.codeplex.com/wikipage?title=Adding%20Custom%20Queries%20to%20Repository&referringTitle=Documentation.

You need to access the IQueryable for Book as follows:

var books = repository.GetRepository<Book>().Queryable();
Marked as answer by lelong37 on 7/3/2014 at 10:00 AM