Error passing in func<type, bool> as a parameter to an async method

c#, entity-framework-6, task-parallel-library

Solution

Your `.Where( predicate )` is using the `IEnumerable.Where` extension method, not `IQueryable.Where`.

This means, the predicate is being run in your app, not on the database server.

If you want to use `IQueryable.Where`, you must pass your predicate as an `Expression<Func<type, bool>>` - an expression tree - not as a delegate.

So, just change your method signature to:

public async Task<IEnumerable<Type>>
  GetTypeSet(Expression<Func<Type, bool>> predicate)
{
  ...

Problem

I am modifying an existing project to take advantage of EF6 (alpha3) async extension methods. I have one method that takes a func parameter, which is passed into the linq to entities query. Here is an example of the working code, pre-async: ``` public IEnumerable<type> GetTypeSet(Func<Type, bool> predicate) { return dbSet.Where(d => d.isPublic == true).Where(predicate).tolist(); } ``` After applying async: ``` public async Task<IEnumerable<Type>> GetTypeSet(Func<Type, bool> predicate) { return await(dbSet.Where(d => d.isPublic == true) .Where(predicate)).ToListAsync(); } ``` At this point, I get an error stating that IEnumerable does not have a definition for ToListAsync. If I remove `.Where(predicate)` it functions correctly. I am curious if I am going about this correctly, or if there is a better option for passing in a predicate when working async.

Original source