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.GetConstructor(
                BindingFlags.NonPublic | BindingFlags.Instance,
                null,
                new Type[] { typeof(Expression), typeof(DataServiceQueryProvider) },
                null);

            return((IQueryable)Util.ConstructorInvoke(ci, args));
        }
Esempio n. 2
0
        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 ResourceSetExpression to new type
        /// </summary>
        internal override ResourceExpression CreateCloneWithNewType(Type type)
        {
            ResourceSetExpression rse = new ResourceSetExpression(
                type,
                this.source,
                this.MemberExpression,
                TypeSystem.GetElementType(type),
                this.ExpandPaths.ToList(),
                this.CountOption,
                this.CustomQueryOptions.ToDictionary(kvp => kvp.Key, kvp => kvp.Value),
                this.Projection);

            rse.keyFilter            = this.keyFilter;
            rse.sequenceQueryOptions = this.sequenceQueryOptions;
            rse.transparentScope     = this.transparentScope;
            return(rse);
        }
Esempio n. 4
0
        internal void AppendToPath(PropertyInfo pi)
        {
            Debug.Assert(pi != null, "pi != null");

            StringBuilder sb;
            Type          t = TypeSystem.GetElementType(pi.PropertyType);

            if (ClientType.CheckElementTypeIsEntity(t))
            {
                // an entity, so need to append to expand path also
                sb = expandPaths.Last();
                Debug.Assert(sb != null);  // there should always be an expand path because must call StartNewPath first.
                if (sb.Length > 0)
                {
                    sb.Append(UriHelper.FORWARDSLASH);
                }

                sb.Append(pi.Name);
            }

            sb = projectionPaths.Last();
            Debug.Assert(sb != null, "sb != null -- we are always building paths in the context of a parameter");

            RemoveEntireEntityMarkerIfPresent(sb);

            if (sb.Length > 0)
            {
                sb.Append(UriHelper.FORWARDSLASH);
            }

            sb.Append(pi.Name);

            if (ClientType.CheckElementTypeIsEntity(t))
            {
                AddEntireEntityMarker(sb);
            }
        }
        internal void AppendToPath(PropertyInfo pi)
        {
            Debug.Assert(pi != null, "pi != null");

            StringBuilder sb;
            Type          t = TypeSystem.GetElementType(pi.PropertyType);

            if (ClientType.CheckElementTypeIsEntity(t))
            {
                sb = expandPaths.Last();
                Debug.Assert(sb != null);
                if (sb.Length > 0)
                {
                    sb.Append(UriHelper.FORWARDSLASH);
                }

                sb.Append(pi.Name);
            }

            sb = projectionPaths.Last();
            Debug.Assert(sb != null, "sb != null -- we are always building paths in the context of a parameter");

            RemoveEntireEntityMarkerIfPresent(sb);

            if (sb.Length > 0)
            {
                sb.Append(UriHelper.FORWARDSLASH);
            }

            sb.Append(pi.Name);

            if (ClientType.CheckElementTypeIsEntity(t))
            {
                AddEntireEntityMarker(sb);
            }
        }
Esempio n. 6
0
        /// <summary>Create a request for a specific Uri</summary>
        /// <param name="requestUri">The URI for the request.</param>
        public DataServiceRequest(Uri requestUri)
        {
            Util.CheckArgumentNull(requestUri, "requestUri");
            Type elementType = typeof(TElement);

            elementType          = ClientConvert.IsKnownType(elementType) ? elementType : TypeSystem.GetElementType(elementType);
            this.queryComponents = new QueryComponents(requestUri, Util.DataServiceVersionEmpty, elementType, null, null);
        }
Esempio n. 7
0
 internal override ResourceExpression CreateCloneWithNewType(Type type)
 {
     return(this.CreateCloneWithNewTypes(type, TypeSystem.GetElementType(type)));
 }
 internal override ResourceExpression CreateCloneWithNewType(Type type)
 {
     return(new NavigationPropertySingletonExpression(type, base.source, this.MemberExpression, TypeSystem.GetElementType(type), this.ExpandPaths.ToList <string>(), this.CountOption, this.CustomQueryOptions.ToDictionary <KeyValuePair <ConstantExpression, ConstantExpression>, ConstantExpression, ConstantExpression>(kvp => kvp.Key, kvp => kvp.Value), base.Projection, base.ResourceTypeAs, base.UriVersion));
 }
Esempio n. 9
0
        /// <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.DataServiceVersionEmpty, elementType, null, null);
            }

            return(this.queryComponents);
        }
Esempio n. 10
0
 internal override System.Data.Services.Client.QueryComponents QueryComponents(DataServiceProtocolVersion maxProtocolVersion)
 {
     if (this.queryComponents == null)
     {
         Type type = typeof(TElement);
         type = (PrimitiveType.IsKnownType(type) || WebUtil.IsCLRTypeCollection(type, maxProtocolVersion)) ? type : TypeSystem.GetElementType(type);
         this.queryComponents = new System.Data.Services.Client.QueryComponents(this.requestUri, Util.DataServiceVersionEmpty, type, null, null);
     }
     return(this.queryComponents);
 }