/// <summary> /// Internal use only - part of <see cref="IQueryProvider"/> implementation. /// </summary> /// <param name="expression"></param> /// <returns></returns> IQueryable IQueryProvider.CreateQuery(Expression expression) { // Not sure when this is called but it IS called on OfType() resolution var methodExpr = (MethodCallExpression)expression; // return type will be an IQueryable<X> var returnType = methodExpr.Method.ReturnType; // extract X var typeT = TypeFns.GetGenericArgument(returnType); // now do the equivalent of => return new EntityQuery<{typeT}>(expression, this); var query = TypeFns.ConstructGenericInstance(typeof(EntityQuery <>), new Type[] { typeT }, expression, this); return((IQueryable)query); }