Probably really simple so please excuse my ignorance…
To my knowledge, there are a couple flavours of the Where() extension method:
Queryable.Where<TSource> Method (IQueryable<TSource>, Expression<Func<TSource, Boolean>>)
Enumerable.Where<TSource> Method (IEnumerable<TSource>, Func<TSource, Boolean>)
Both of the above extensions are housed in the System.Linq namespace, so that I can do Where() at all is hopefully proof enough that I’ve imported the correct namespace – or is there another namespace I need for IQueryable extensions?
I understand that IQueryable<T> inherits from IEnumerable<T> but why can’t I get the IQueryable<T> extensions?
class Test
{
IQueryable<Test> SomeMethod(Func<T, bool> criteria)
{
return new List<Test> { new Test() }.AsQueryable().Where(criteria); // compiler error converting IEnumerable<T> to IQueryable<T>
}
}
As shown above, there should be an extension method available that returns IQueryable? Why is it resolving to the IEnumerable Extensions?
The Queryable.Where Extension Method expects an
Expression<Func<T, bool>>(i.e. an expression tree representing a lambda), not aFunc<T, bool>(a lambda itself).This works: