当前位置: 首页>>代码示例>>C#>>正文


C# IQueryable.GetType方法代码示例

本文整理汇总了C#中IQueryable.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.GetType方法的具体用法?C# IQueryable.GetType怎么用?C# IQueryable.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IQueryable的用法示例。


在下文中一共展示了IQueryable.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplySelectAndExpand

        public IQueryable ApplySelectAndExpand(IQueryable queryable, HttpRequestMessage request )
        {
            var result = queryable;
              var hasSelectOrExpand = false;

              var map = request.RequestUri.ParseQueryString();

              var selectQueryString = map["$select"];
              if (!string.IsNullOrWhiteSpace(selectQueryString)) {
            var selectClauses = selectQueryString.Split(',').Select(sc => sc.Replace('/', '.')).ToList();
            var elementType = TypeFns.GetElementType(queryable.GetType());
            var func = QueryBuilder.BuildSelectFunc(elementType, selectClauses);
            result = func(result);
            hasSelectOrExpand = true;
              }

              var expandsQueryString = map["$expand"];
              if (!string.IsNullOrWhiteSpace(expandsQueryString)) {
            if (!string.IsNullOrWhiteSpace(selectQueryString)) {
              throw new Exception("Use of both 'expand' and 'select' in the same query is not currently supported");
            }
            expandsQueryString.Split(',').Select(s => s.Trim()).ToList().ForEach(expand => {
              result = ((dynamic) result).Include(expand.Replace('/', '.'));
            });
            hasSelectOrExpand = true;
              }

              return hasSelectOrExpand ? result : null;
        }
开发者ID:kangu,项目名称:Breeze,代码行数:29,代码来源:BreezeQueryableAttribute.cs

示例2: QuerySourceExpression

 public QuerySourceExpression(string alias, IQueryable query, System.Type elementType)
     : base(NHibernateExpressionType.QuerySource, query.GetType())
 {
     _alias = alias;
     _query = query;
     _elementType = elementType;
 }
开发者ID:jonhilt,项目名称:Who-Can-Help-Me,代码行数:7,代码来源:QuerySourceExpression.cs

示例3: AddSchemaToModel

        internal static void AddSchemaToModel(IQueryable query)
        {
            var dataContext = GetFieldValue(query.GetType(), query, "context", BindingFlags.NonPublic | BindingFlags.Instance) as DataContext;
            if (dataContext == null)
            {
                return;
            }

            var services = GetFieldValue(typeof(DataContext), dataContext, "services", BindingFlags.Instance | BindingFlags.NonPublic);
            if (services == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var metaModelFieldInfo = services.GetType().GetField("metaModel", BindingFlags.Instance | BindingFlags.NonPublic);
            if (metaModelFieldInfo == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var metaModel = metaModelFieldInfo.GetValue(services);
            if (metaModel is CustomMetaModel == false)
            {
                metaModelFieldInfo.SetValue(services, new CustomMetaModel((MetaModel)metaModel));
            }
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:26,代码来源:LinqToSql.cs

示例4: BaseCollectionResult

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseCollectionResult" /> class.
        /// </summary>
        /// <param name="query">The query that returns a collection of objects.</param>
        /// <param name="edmType">The EDM type reference of the objects.</param>
        /// <param name="context">The context where the action is executed.</param>
        protected BaseCollectionResult(IQueryable query, IEdmTypeReference edmType, ApiContext context)
            : base(edmType, context)
        {
            Ensure.NotNull(query, "query");

            this.Query = query;
            this.Type = query.GetType();
        }
开发者ID:kosinsky,项目名称:RESTier,代码行数:14,代码来源:BaseCollectionResult.cs

示例5: GetConnectionString

        internal static string GetConnectionString(IQueryable query)
        {
            ArgumentValidator.IsNotNull(query, "query");

            var queryType = query.GetType();
            var providerProperty = queryType.GetProperty(Provider, BindingFlags.Instance | BindingFlags.NonPublic);
            if (providerProperty == null)
            {
                var queryBaseType = queryType.BaseType;
                if (queryBaseType == null)
                {
                    throw LinqCacheException.ContextIsNotSupported;
                }

                providerProperty = queryBaseType.GetProperty(Provider, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (providerProperty == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var provider = providerProperty.GetValue(query);
            if (provider == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var contextField = provider.GetType().GetField("_internalContext", BindingFlags.Instance | BindingFlags.NonPublic);
            if (contextField == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var context = contextField.GetValue(provider);
            if (context == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var connectionProperty = context.GetType().GetProperty("Connection");
            if (connectionProperty == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            var connection = connectionProperty.GetValue(context) as IDbConnection;
            if (connection == null)
            {
                throw LinqCacheException.ContextIsNotSupported;
            }

            return connection.ConnectionString;
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:54,代码来源:EntityFramework.cs

示例6: Apply

        public IQueryable Apply(IQueryable queryable)
        {
            // Skip does not work on queryables by default, because it makes
            // no sense if the order is not determined. This means we have to
            // order the queryable first, before we can apply pagination.
            var isOrdered = queryable.GetType().GetInterfaces()
                .Where(i => i.IsGenericType)
                .Any(i => i.GetGenericTypeDefinition() == typeof(IOrderedQueryable<>));

            var ordered = isOrdered ? queryable : OrderById(queryable);

            var filtered = ordered.ApplyQuery(QueryMethod.Skip, _context.Page * _context.PerPage) as IQueryable;
            filtered = filtered.ApplyQuery(QueryMethod.Take, _context.PerPage) as IQueryable;

            return filtered;
        }
开发者ID:markwalsh-liverpool,项目名称:saule,代码行数:16,代码来源:PaginationInterpreter.cs

示例7: GetDataContext

        public static DataContext GetDataContext(IQueryable query)
        {
            if (query == null)
                return null;

            Type type = query.GetType();
            FieldInfo field = type.GetField("context", BindingFlags.NonPublic | BindingFlags.Instance);
            if (field == null)
                return null;

            object value = field.GetValue(query);
            if (value == null)
                return null;

            var dataContext = value as DataContext;
            return dataContext;
        }
开发者ID:mattfrerichs,项目名称:Templates,代码行数:17,代码来源:LinqToSqlDataContextProvider.cs

示例8: GetConnectionString

        internal static string GetConnectionString(IQueryable query)
        {
            ArgumentValidator.IsNotNull(query, "query");

            var queryType = query.GetType();
            var providerProperty = queryType.GetProperty(Provider, BindingFlags.Instance | BindingFlags.NonPublic);

            if (providerProperty == null)
            {
                return null;
            }

            var provider = providerProperty.GetValue(query);
            if (provider == null)
            {
                return null;
            }

            var contextField = provider.GetType().GetField("context", BindingFlags.Instance | BindingFlags.NonPublic);
            if (contextField == null)
            {
                return null;
            }

            var context = contextField.GetValue(provider);
            if (context == null)
            {
                return null;
            }

            var connectionProperty = context.GetType().GetProperty("Connection");
            if (connectionProperty == null)
            {
                return null;
            }

            var connection = connectionProperty.GetValue(context) as IDbConnection;
            if (connection == null)
            {
                return null;
            }

            return connection.ConnectionString;
        }
开发者ID:david0718,项目名称:LinqCache,代码行数:44,代码来源:LinqToSql.cs

示例9: LoadQuery

        public static IEnumerable LoadQuery(this ClientContext clientContext, IQueryable query)
        {
            if (clientContext == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(clientContext));
            }

            if (query == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(query));
            }

            var elementType = GetQueryableElementTypes(query.GetType()).FirstOrDefault();

            if (elementType == null)
            {
                throw Logger.Fatal.ArgumentNotAssignableTo(nameof(query), query, typeof(IQueryable<>));
            }

            return (IEnumerable)LoadQueryMethod
                .MakeGenericMethod(elementType)
                .Invoke(clientContext, new[] { query });
        }
开发者ID:NaseUkolyCZ,项目名称:HarshPoint,代码行数:23,代码来源:ClientContextExtensions.cs

示例10: ApplyExtendedOrderBy

        private IQueryable ApplyExtendedOrderBy(IQueryable queryable, ODataQueryOptions queryOptions)
        {
            var orderByQueryString = queryOptions.RawValues.OrderBy;
              if (orderByQueryString == null || orderByQueryString.IndexOf("/") == -1) {
            return null;
              }

              var request = queryOptions.Request;
              var oldUri = request.RequestUri;
              var map = oldUri.ParseQueryString();
              var newQuery = map.Keys.Cast<String>()
                        .Where(k => k != "$orderby")
                        .Select(k => k + "=" + map[k])
                        .ToAggregateString("&");

              var newUrl = oldUri.Scheme + "://" + oldUri.Authority + oldUri.AbsolutePath + "?" + newQuery;

              var newRequest = new HttpRequestMessage(request.Method, new Uri(newUrl));
              var newQo = new ODataQueryOptions(queryOptions.Context, newRequest);
              var result = base.ApplyQuery(queryable, newQo);

              var elementType = TypeFns.GetElementType(queryable.GetType());

              if (!string.IsNullOrWhiteSpace(orderByQueryString)) {
            var orderByClauses = orderByQueryString.Split(',').ToList();
            var isThenBy = false;
            orderByClauses.ForEach(obc => {
              var func = QueryBuilder.BuildOrderByFunc(isThenBy, elementType, obc);
              result = func(result);
              isThenBy = true;
            });
              }
              request.Properties.Add("breeze_orderBy", true);
              return result;
        }
开发者ID:kangu,项目名称:Breeze,代码行数:35,代码来源:BreezeQueryableAttribute.cs

示例11: ExecuteQuery

        protected override IQueryable ExecuteQuery(IQueryable source, QueryContext context)
        {
            // If we're not supposed to retrieve the total row count, just call the base
            if (!context.Arguments.RetrieveTotalRowCount)
                return base.ExecuteQuery(source, context);

            // Turn that off so that the base implementation won't make a count request
            context.Arguments.RetrieveTotalRowCount = false;

            // Call the base to build the query
            source = base.ExecuteQuery(source, context);

            // Include the total Row Count as part of the data query, to avoid making two separate queries
            MethodInfo includeTotalCountMethod = source.GetType().GetMethod("IncludeTotalCount");
            if (includeTotalCountMethod == null)
                return source;

            source = (IQueryable)includeTotalCountMethod.Invoke(source, null);

            // Execute the query
            MethodInfo executeMethod = source.GetType().GetMethod("Execute");
            var queryOperationResponse = (QueryOperationResponse)executeMethod.Invoke(source, null);

            // Get the count and set it in the Arguments
            context.Arguments.TotalRowCount = (int)queryOperationResponse.TotalCount;

            // Return it as an IQueryable.
            // Note that we end up returning an executed query, while the base implementation doesn't.
            // But this should be harmless, since all the LINQ operations were already included in the query
            return queryOperationResponse.AsQueryable();
        }
开发者ID:davidebbo-test,项目名称:DynamicDataWCFDataService,代码行数:31,代码来源:DataServiceLinqDataSource.cs

示例12: GetQueryable

        public override IQueryable GetQueryable(IQueryable source) {
            if (source == null) {
                throw new ArgumentNullException("source");
            }

            MethodInfo method = ResolveMethod();

            // Get the parameter values
            IDictionary<string, object> parameterValues = GetValues();

            if (method == null) {
                if (IgnoreIfNotFound) {
                    // Unchange the IQueryable if the user set IgnoreIfNotFound
                    return source;
                }
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
                    AtlasWeb.MethodExpression_MethodNotFound, MethodName));
            }

            if(!method.IsStatic) {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                    AtlasWeb.MethodExpression_MethodMustBeStatic, MethodName));
            }

            ParameterInfo[] parameterArray = method.GetParameters();
            if (parameterArray.Length == 0 || !parameterArray[0].ParameterType.IsAssignableFrom(source.GetType())) {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.MethodExpression_FirstParamterMustBeCorrectType,
                    MethodName, source.GetType()));
            }

            object[] arguments = new object[parameterArray.Length];
            // First argument is the IQueryable
            arguments[0] = source;
            for (int i = 1; i < parameterArray.Length; ++i) {
                ParameterInfo param = parameterArray[i];
                object value;
                if (!parameterValues.TryGetValue(param.Name, out value)) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                        AtlasWeb.MethodExpression_ParameterNotFound, MethodName, param.Name));
                }

                arguments[i] = DataSourceHelper.BuildObjectValue(value, param.ParameterType, param.Name);
            }

            object result = method.Invoke(null, arguments);

            // Require the return type be the same as the parameter type
            if (result != null) {
                IQueryable queryable = result as IQueryable;
                // Check if the user did a projection (changed the T in IQuerable<T>)
                if (queryable == null || !queryable.ElementType.IsAssignableFrom(source.ElementType)) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.MethodExpression_ChangingTheReturnTypeIsNotAllowed,
                                                        source.ElementType.FullName));
                }
            }

            return (IQueryable)result;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:58,代码来源:MethodExpression.cs

示例13: SetContinuationToken

        /// <summary>
        /// Gets the next-page token from the $skiptoken query option in the request URI.
        /// </summary>
        /// <param name="query">Query for which the continuation token is being provided.</param>
        /// <param name="resourceType">Resource type of the result on which the $skip token is to be applied.</param>
        /// <param name="continuationToken">Continuation token parsed into primitive type values.</param>
        public virtual void SetContinuationToken(IQueryable query, ResourceType resourceType, object[] continuationToken)
        {
            if (IsTopRequest())
                return;

            var instanceType = resourceType.InstanceType;
            var queryType = typeof(ODataQuery<>).MakeGenericType(instanceType);
            this.expression = query.Expression;
            this.queryProvider = query.Provider;

            if (queryType.IsAssignableFrom(query.GetType()))
            {
                if (this.SupportsType(instanceType))
                {
                    if (continuationToken != null && continuationToken[0] != null)
                    {
                        var token = Encoding.Default.GetString(Convert.FromBase64String(continuationToken[0].ToString()));
                        var tokenParts = token.Split(':');
                        this.entityTypeName = tokenParts[0];
                        this.lastReceivedPage = Convert.ToInt32(tokenParts[1]);
                    }
                    else
                    {
                        this.entityTypeName = instanceType.Name;
                        this.lastReceivedPage = 1;
                    }

                    var provider = queryType.GetProperty("Provider").GetValue(query, null);
                    var skip = (this.lastReceivedPage * this.PageSizeFor(instanceType)) - this.PageSizeFor(instanceType);
                    var nextContinuationToken = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", skip + this.CurrentOffset(), this.PageSizeFor(instanceType));
                    provider.GetType().GetProperty("ContinuationToken").SetValue(provider, nextContinuationToken, null);
                    provider.GetType().GetProperty("SkipTakeBasedPaging").SetValue(provider, true, null);
                }
            }
        }
开发者ID:baio,项目名称:Microsoft.Data.Services.Toolkit,代码行数:41,代码来源:GenericPagingProvider.cs

示例14: TryConvertToFilteredCollection

        private static List<object> TryConvertToFilteredCollection(IQueryable collection, NameValueCollection queryString, out int returnedTotal)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (!collection.GetType().IsGenericType || collection.GetType().GetGenericTypeDefinition().GetInterface(typeof(IQueryable<>).FullName) == null)
            {
                collection = collection.Cast<object>();
            }

            try
            {
                Type modelType = collection.GetType().GetGenericArguments()[0];
                Type parserType = typeof(ParameterParser<>).MakeGenericType(modelType);

                var parser = Activator.CreateInstance(parserType);
                var filter = parserType.GetMethod("Parse").Invoke(parser, new object[] { queryString });
                var filteredCollection = filter != null ? filter.GetType().GetMethod("Filter").Invoke(filter, new object[] { collection }) : collection;

                if (!String.Equals(InlineCountValue, queryString.Get(InlineCountKey), StringComparison.OrdinalIgnoreCase))
                {
                    returnedTotal = -1;
                }
                else if (queryString.Get(TopKey) == null && queryString.Get(SkipKey) == null)
                {
                    returnedTotal = Queryable.Count((dynamic) filteredCollection);
                }
                else
                {
                    var totalQueryString = new NameValueCollection(queryString);
                    totalQueryString.Remove(TopKey);
                    totalQueryString.Remove(SkipKey);

                    var totalFilter = parserType.GetMethod("Parse").Invoke(parser, new object[] { totalQueryString });
                    var totalFilteredCollection = filter != null ? filter.GetType().GetMethod("Filter").Invoke(totalFilter, new object[] { collection }) : collection;
                    returnedTotal = Queryable.Count((dynamic) totalFilteredCollection);
                }

                return new List<object>((IQueryable<object>) filteredCollection);
            }
            catch (Exception)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest, Global.InvalidODataParameters);
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:47,代码来源:Linq2RestODataProvider.cs


注:本文中的IQueryable.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。