ToListAsync returns InvalidOperationException. Loading a collection async

Jun 2, 2014 at 8:48 AM
I want to get all roles in a OU Async. FirstorDefaultAsync works great, but when retrieving a collection it returns:

"System.InvalidOperationException: The source IQueryable doesn't implement IDbAsyncEnumerable. Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations. For more details see"

My code is:
     var roles = context
                    .Query(Config.AdRoleLocation, objectClass: "group");
     return await roles.ToListAsync(new CancellationToken());
Are there any way of loading a collection Async? I have tried LoadAsync/any/all..
Jun 2, 2014 at 10:14 AM
The issue was that my class had:
using System.Data.Entity;
And since both and linqtoldap has the same name on the extension method ToListAsync() there was no way of only using the linqtoldap extension.
Would it be an idea to implement IDbAsyncEnumerable in LinqToLdap and use the extentions from EntityFramework 6?
Marked as answer by bjalla on 6/2/2014 at 3:14 AM
Jun 3, 2014 at 6:45 PM
IDbAsyncEnumerable is an Entity Framework specific interface. You have a couple of options to solve this:

You can use the fully qualified static method from Linq To Ldap:
return await LinqToLdap.QueryableAsyncExtensions.ToListAsync(roles);
Or you can just use Task.Run or Task.Factory.StartNew:
return await Task.Run(() => roles.ToList(), new CancellationToken());
return await Task.Factory.StartNew(() => roles.ToList(), new CancellationToken());