本文整理汇总了C#中HttpRequest.ODataProperties方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.ODataProperties方法的具体用法?C# HttpRequest.ODataProperties怎么用?C# HttpRequest.ODataProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.ODataProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyQueryOptions
public virtual object ApplyQueryOptions(object value, HttpRequest request, ActionDescriptor actionDescriptor, AssembliesResolver assembliesResolver)
{
var elementClrType = value is IEnumerable
? TypeHelper.GetImplementedIEnumerableType(value.GetType())
: value.GetType();
var model = request.ODataProperties().Model;
if (model == null)
{
throw Error.InvalidOperation(SRResources.QueryGetModelMustNotReturnNull);
}
var queryContext = new ODataQueryContext(
model,
elementClrType,
assembliesResolver,
request.ODataProperties().Path
);
var queryOptions = new ODataQueryOptions(queryContext, request, assembliesResolver);
var enumerable = value as IEnumerable;
if (enumerable == null)
{
// response is single entity.
return value;
}
// response is a collection.
var query = (value as IQueryable) ?? enumerable.AsQueryable();
query = queryOptions.ApplyTo(query,
new ODataQuerySettings
{
// TODO: If we are using SQL, set this to false
// otherwise if it is entities in code then
// set it to true
HandleNullPropagation =
//HandleNullPropagationOption.True
HandleNullPropagationOptionHelper.GetDefaultHandleNullPropagationOption(query),
PageSize = actionDescriptor.PageSize(),
SearchDerivedTypeWhenAutoExpand = true
},
AllowedQueryOptions.None);
// Determine if this result should be a single entity
if (ODataCountMediaTypeMapping.IsCountRequest(request))
{
long? count = request.ODataProperties().TotalCount;
if (count.HasValue)
{
// Return the count value if it is a $count request.
return count.Value;
}
}
return query;
}
示例2: IsCountRequest
///// <summary>
///// Initializes a new instance of the <see cref="ODataCountMediaTypeMapping"/> class.
///// </summary>
//public ODataCountMediaTypeMapping()
// : base("text/plain")
//{
//}
///// <inheritdoc/>
//public override double TryMatchMediaType(HttpRequestMessage request)
//{
// if (request == null)
// {
// throw Error.ArgumentNull("request");
// }
// return IsCountRequest(request) ? 1 : 0;
//}
internal static bool IsCountRequest(HttpRequest request)
{
ODataPath path = request.ODataProperties().Path;
return path != null && path.Segments.LastOrDefault() is CountPathSegment;
}