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


C# IQueryable.Cast方法代码示例

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


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

示例1: AddTemplatesPredicate

 private IQueryable<SearchResultItem> AddTemplatesPredicate(IQueryable<SearchResultItem> query)
 {
   if (DatasourceTemplate == null)
   {
     return query;
   }
   var templateId = IdHelper.NormalizeGuid(DatasourceTemplate.ID);
   return query.Cast<SearchResult>().Where(x => x.Templates.Contains(templateId));
 }
开发者ID:varunvns,项目名称:Habitat,代码行数:9,代码来源:QueryableDatasourceRenderingModel.cs

示例2: GetResource

        /// <summary>
        /// Gets the resource of the specified type identified by a query and type name. 
        /// </summary>
        /// <returns>
        /// An opaque object representing a resource of the specified type, referenced by the specified query.
        /// </returns>
        /// <param name="query">Language integrated query (LINQ) pointing to a particular resource.</param><param name="fullTypeName">The fully qualified type name of resource.</param>
        public object GetResource(IQueryable query, string fullTypeName)
        {
            var resource = query.Cast<object>().SingleOrDefault();

            // fullTypeName can be null for deletes
            if (fullTypeName != null && (resource == null || resource.GetType().FullName != fullTypeName))
                throw new InvalidOperationException("Unexpected type for resource.");

            return resource;
        }
开发者ID:alexey-kadyrov,项目名称:DocaLabs-Utils,代码行数:17,代码来源:ProductDataSource.cs

示例3: Exception

        object IUpdatable.GetResource(IQueryable query, string fullTypeName)
        {
            // here the GET query is executed
            object resource = query.Cast<object>().Single();

            if ((fullTypeName != null) && (resource.GetType().FullName != fullTypeName))
            {
                throw new Exception(string.Format("Unexpected type {0} for resource", fullTypeName));
            }

            return resource;
        }
开发者ID:LCHarold,项目名称:linq2dynamodb,代码行数:12,代码来源:UpdatableDataContext.cs

示例4: BuildCommodityInstrumentTypes

        public CommodityInstrumentTypeList BuildCommodityInstrumentTypes(IQueryable data)
        {
            var commodityInstrumentTypes = new CommodityInstrumentTypeList();

            var adcCommodityList = data.Cast<PartyCrossMap>()
                                    .Where(x => x.Commodity != null)
                                    .Select(x => x.Commodity)
                                    .Distinct()
                                    .ToList();

            foreach (var adcCommodity in adcCommodityList)
            {
                if (string.IsNullOrWhiteSpace(adcCommodity))
                {
                    continue;
                }

                var nexusId = new MdmId
                {
                    Identifier = adcCommodity,
                    SourceSystemOriginated = false,
                    IsMdmId = false,
                    SystemName = "ADC"
                };

                var commodity = this.GetCommodity(adcCommodity);
                var instrumentType = this.GetInstrumentType(adcCommodity);
                var instrumentDelivery = this.GetInstrumentDelivery(adcCommodity);

                if (commodity == null)
                {
                    continue;
                }

                var commodityInstrumentType = new CommodityInstrumentType
                    {
                        Identifiers = new MdmIdList { nexusId },
                        Details =
                            {
                                Commodity = commodity,
                                InstrumentType = instrumentType,
                                InstrumentDelivery = instrumentDelivery
                            }
                    };

                commodityInstrumentTypes.Add(commodityInstrumentType);
            }

            return commodityInstrumentTypes;
        }
开发者ID:RaoulHolzer,项目名称:EnergyTrading-MDM-Sample,代码行数:50,代码来源:CommodityInstrumentTypeBuilder.cs

示例5: GetPackageInfos

        private static IQueryable<PackageInfo> GetPackageInfos(IQueryable<IPackage> query, IPackageRepository repository, bool showPrerelease)
        {
            if (repository is DataServicePackageRepository)
            {
                if (showPrerelease)
                {
                    query = query.Where(p => p.IsAbsoluteLatestVersion);
                }
                else
                {
                    query = query.Where(p => p.IsLatestVersion);
                }

                return query.Cast<DataServicePackage>().Select(p => new PackageInfo
                                                        {
                                                            Id = p.Id,
                                                            Version = p.Version,
                                                            Authors = p.Authors,
                                                            DownloadCount = p.DownloadCount,
                                                            VersionDownloadCount = p.VersionDownloadCount,
                                                            PackageHash = p.PackageHash,
                                                            PackageSize = p.PackageSize,
                                                            Published = p.Published
                                                        });
            }
            else
            {
                query = query.GroupBy(p => p.Id, StringComparer.OrdinalIgnoreCase)
                             .Select(g => g.OrderByDescending(p => p.Version)
                             .First());

                return query.Cast<ZipPackage>().Select(p => new PackageInfo
                                                    {
                                                        Id = p.Id,
                                                        Version = p.Version.ToString(),
                                                        Authors = String.Join(", ", p.Authors),
                                                        DownloadCount = p.DownloadCount,
                                                        VersionDownloadCount = p.VersionDownloadCount,
                                                        PackageHash = p.PackageHash,
                                                        PackageSize = p.PackageSize,
                                                        DownloadUrl = new Uri(p.Source),
                                                        Published = p.Published,
                                                    });
            }
        }
开发者ID:304NotModified,项目名称:NuGetPackageExplorer-1,代码行数:45,代码来源:PackageChooserViewModel.cs

示例6: FilterOnTemplates

 private IQueryable<SearchResultItem> FilterOnTemplates(IQueryable<SearchResultItem> queryable)
 {
   var indexedItemPredicate = GetPredicateForItemDerivesFromIndexedItem();
   var contentTemplatePredicates = this.GetPredicatesForContentTemplates();
   return queryable.Cast<IndexedItem>().Where(indexedItemPredicate.And(contentTemplatePredicates));
 }
开发者ID:robearlam,项目名称:Habitat,代码行数:6,代码来源:SearchService.cs

示例7: FilterOnVersion

 private static IQueryable<SearchResultItem> FilterOnVersion(IQueryable<SearchResultItem> queryable)
 {
   queryable = queryable.Cast<IndexedItem>().Filter(item => item.IsLatestVersion);
   return queryable;
 }
开发者ID:robearlam,项目名称:Habitat,代码行数:5,代码来源:SearchService.cs

示例8: FilterOnPresentationOnly

 private IQueryable<SearchResultItem> FilterOnPresentationOnly(IQueryable<SearchResultItem> queryable)
 {
   return queryable.Cast<IndexedItem>().Where(i => i.HasPresentation && i.ShowInSearchResults);
 }
开发者ID:robearlam,项目名称:Habitat,代码行数:4,代码来源:SearchService.cs

示例9: FilterOnHasSearchResultFormatter

 private IQueryable<SearchResultItem> FilterOnHasSearchResultFormatter(IQueryable queryable)
 {
     return queryable.Cast<IndexedItem>().Where(i => i.HasSearchResultFormatter);
 }
开发者ID:BIGANDYT,项目名称:Spitfire,代码行数:4,代码来源:SearchService.cs

示例10: GetPackageInfos

 private static IQueryable<PackageInfo> GetPackageInfos(IQueryable<IPackage> query, IPackageRepository repository)
 {
     if (repository is DataServicePackageRepository)
     {
         return query.Cast<DataServicePackage>().Select(p => new PackageInfo
             {
                 Id = p.Id,
                 Version = p.Version,
                 Authors = p.Authors,
                 DownloadCount = p.DownloadCount,
                 VersionDownloadCount = p.VersionDownloadCount,
                 PackageHash = p.PackageHash,
                 PackageSize = p.PackageSize,
                 Published = p.Published
             });
     }
     else
     {
         return query.Cast<ZipPackage>().Select(p => new PackageInfo
             {
                 Id = p.Id,
                 Version = p.Version.ToString(),
                 Authors = String.Join(", ", p.Authors),
                 DownloadCount = p.DownloadCount,
                 VersionDownloadCount = p.VersionDownloadCount,
                 PackageHash = p.PackageHash,
                 PackageSize = p.PackageSize,
                 DownloadUrl = new Uri(p.Source),
                 Published = p.Published,
             });
     }
 }
开发者ID:campersau,项目名称:NuGetPackageExplorer,代码行数:32,代码来源:PackageInfoViewModel.cs

示例11: GetResource

        /// <summary>
        /// 获得查询指向的给定类型的资源
        /// </summary>
        /// <param name="query">查询指向一个特定的资源
        /// </param>
        /// <param name="fullTypeName">程序集限定名
        /// </param>
        /// <returns>一个给定类型的资源对象以及引用它的查询
        /// </returns>
        public object GetResource(IQueryable query, string fullTypeName)
        {
            object resource = query.Cast<object>().SingleOrDefault();

            // 对 Delegate 类型来说,程序集限定名可以为null
            if (fullTypeName != null && resource.GetType().FullName !=
                fullTypeName)
                throw new Exception("未知的对象");
            return resource;
        }
开发者ID:zealoussnow,项目名称:OneCode,代码行数:19,代码来源:IUpdatableLinqToSQL.cs

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