Exemplo n.º 1
0
        private static EntityQuery AddWhereClause(EntityQuery entityQuery, LambdaExpression lambda)
        {
            // This works too - not sure which is faster or better
            //var method = factory.GetType().GetMethod("Where", new Type[] { typeof(LambdaExpression) });
            //var query = method.Invoke(factory, new Object[] { lambda });
            //return (EntityQuery)query;
            var expr  = BuildCallWhereExpr(entityQuery, lambda);
            var query = (EntityQuery)TypeFns.ConstructGenericInstance(typeof(EntityQuery <>),
                                                                      new Type[] { entityQuery.ElementType },
                                                                      expr, entityQuery);

            return(query);
        }
Exemplo n.º 2
0
        /// <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);
        }