本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}
示例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,
});
}
}
示例6: FilterOnTemplates
private IQueryable<SearchResultItem> FilterOnTemplates(IQueryable<SearchResultItem> queryable)
{
var indexedItemPredicate = GetPredicateForItemDerivesFromIndexedItem();
var contentTemplatePredicates = this.GetPredicatesForContentTemplates();
return queryable.Cast<IndexedItem>().Where(indexedItemPredicate.And(contentTemplatePredicates));
}
示例7: FilterOnVersion
private static IQueryable<SearchResultItem> FilterOnVersion(IQueryable<SearchResultItem> queryable)
{
queryable = queryable.Cast<IndexedItem>().Filter(item => item.IsLatestVersion);
return queryable;
}
示例8: FilterOnPresentationOnly
private IQueryable<SearchResultItem> FilterOnPresentationOnly(IQueryable<SearchResultItem> queryable)
{
return queryable.Cast<IndexedItem>().Where(i => i.HasPresentation && i.ShowInSearchResults);
}
示例9: FilterOnHasSearchResultFormatter
private IQueryable<SearchResultItem> FilterOnHasSearchResultFormatter(IQueryable queryable)
{
return queryable.Cast<IndexedItem>().Where(i => i.HasSearchResultFormatter);
}
示例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,
});
}
}
示例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;
}
示例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);
}
}