The main purpose of this interface is to allow access to the ElementType
, Expression
, and Provider
without needing to know the Generic Type.
This is a fairly common practice for Microsoft when writing Generic Types. List<T>
inherits from IList<T>
which inherits from IList
.
In other words you want to expose any property that does not require the generic type in a non generic way. In the case of IQueryable<T>
there is not properties exposed. However, the generic type T
allows for strongly typed extension methods, that are found in System.Linq.Queryable
.
Observe the following:
void Main()
{
var lst = new List<string>();
lst.Add("test1");
lst.Add("test2");
lst.Add("test3");
IQueryable<string> q = lst.AsQueryable();
PrintQueryInfo( q.Where(x=>x.Contains('1')));
}
public void PrintQueryInfo(IQueryable q){
Console.WriteLine(q.Expression.ToString());
}
Output:
System.Collections.Generic.List`1[System.String].Where(x => x.Contains(1))
Its also worth noting that the above example could also be done with a generic method. But this is not always possible or practical.
public void PrintQueryInfo<T>(IQueryable<T> q){
Console.WriteLine(q.Expression.ToString());
}