Sergey
Sergey

Reputation: 8091

Why IQueryable executes in Where clause?

I have

public IQueryable<Guid> AccessibleCities
{
    get
    {
        return CityRepository
            .FindAll(a => <CONDITIONS>);
    }
}

CityRepository.FindAll is implemented as:

public virtual IQueryable<TLookup> FindAll(Expression<Func<TLookup, bool>> predicate)
{
  return DataContext.GetSet<TLookup>().Where(predicate);
}

And I call this

anotherRepository
    .FindAll(a => AccessibleCities.Any(b => ANOTHER CONDITION));

When I call the last one, it generates two queries instead of adding AccessibleCities as query.

Please help me :)

Upvotes: 0

Views: 796

Answers (1)

Bob Horn
Bob Horn

Reputation: 34325

Your final query just doesn't work that way; it doesn't concatenate by default.

Try the PredicateBuilder class. That looks like it should work for what you're trying to achieve.

Upvotes: 1

Related Questions