/// <summary>Factory method for creating DataServiceOrderedQuery based on expression </summary> /// <param name="expression">The expression for the new query</param> /// <returns>new DataServiceQuery</returns> public IQueryable CreateQuery(Expression expression) { Util.CheckArgumentNull(expression, "expression"); Type et = TypeSystem.GetElementType(expression.Type); Type qt = typeof(DataServiceQuery <> .DataServiceOrderedQuery).MakeGenericType(et); object[] args = new object[] { expression, this }; ConstructorInfo ci = qt.GetInstanceConstructor( false /*isPublic*/, new Type[] { typeof(Expression), typeof(DataServiceQueryProvider) }); return((IQueryable)Util.ConstructorInvoke(ci, args)); }
/// <summary> /// Cast changes the type of the ResourceExpression /// </summary> /// <param name="type">new type</param> /// <returns>new NavigationPropertySingletonExpression</returns> internal override ResourceExpression CreateCloneWithNewType(Type type) { return(new NavigationPropertySingletonExpression( type, this.source, this.MemberExpression, TypeSystem.GetElementType(type), this.ExpandPaths.ToList(), this.CountOption, this.CustomQueryOptions.ToDictionary(kvp => kvp.Key, kvp => kvp.Value), this.Projection, this.ResourceTypeAs, this.UriVersion)); }
/// <summary> /// Create a clone with new type. /// </summary> /// <param name="type">The type.</param> /// <returns>The new clone.</returns> internal override ResourceExpression CreateCloneWithNewType(Type type) { QueryableResourceExpression clone = this.CreateCloneWithNewTypes(type, TypeSystem.GetElementType(type)); if (this.keyPredicateConjuncts != null && this.keyPredicateConjuncts.Count > 0) { clone.SetKeyPredicate(this.keyPredicateConjuncts); } clone.keyFilter = this.keyFilter; clone.sequenceQueryOptions = this.sequenceQueryOptions; clone.transparentScope = this.transparentScope; return(clone); }
/// <summary> /// Checks whether the specified expression creates a collection. /// </summary> /// <param name="e">Expression to check.</param> /// <returns>true if given expression is collection producing.</returns> internal static bool IsCollectionProducingExpression(Expression e) { if (TypeSystem.FindIEnumerable(e.Type) != null) { Type elementType = TypeSystem.GetElementType(e.Type); Debug.Assert(elementType != null, "elementType == null"); Type dscType = WebUtil.GetDataServiceCollectionOfT(elementType); if (typeof(List <>).MakeGenericType(elementType).IsAssignableFrom(e.Type) || (dscType != null && dscType.IsAssignableFrom(e.Type))) { return(true); } } return(false); }
/// <summary> /// Cast QueryableResourceExpression to new type without affecting member type /// </summary> /// <param name="type">The new expression type</param> /// <returns>A copy of this with the new types</returns> internal QueryableResourceExpression CreateCloneForTransparentScope(Type type) { // QueryableResourceExpression can always have order information, // so return them as IOrderedQueryable<> always. Necessary to allow // OrderBy results that get aliased to a previous expression work // with ThenBy. Type elementType = TypeSystem.GetElementType(type); Debug.Assert(elementType != null, "elementType != null -- otherwise the set isn't going to act like a collection"); Type newType = typeof(IOrderedQueryable <>).MakeGenericType(elementType); QueryableResourceExpression clone = this.CreateCloneWithNewTypes(newType, this.ResourceType); if (this.keyPredicateConjuncts != null && this.keyPredicateConjuncts.Count > 0) { clone.SetKeyPredicate(this.keyPredicateConjuncts); } clone.keyFilter = this.keyFilter; clone.sequenceQueryOptions = this.sequenceQueryOptions; clone.transparentScope = this.transparentScope; return(clone); }
/// <summary>The QueryComponents associated with this request</summary> /// <param name="model">The client model.</param> /// <returns>an instance of QueryComponents.</returns> internal override QueryComponents QueryComponents(ClientEdmModel model) { if (this.queryComponents == null) { Type elementType = typeof(TElement); // for 1..* navigation properties we need the type of the entity of the collection that is being navigated to. Otherwise we use TElement. elementType = PrimitiveType.IsKnownType(elementType) || WebUtil.IsCLRTypeCollection(elementType, model) ? elementType : TypeSystem.GetElementType(elementType); this.queryComponents = new QueryComponents(this.requestUri, Util.ODataVersionEmpty, elementType, null, null); } return(this.queryComponents); }