本文整理汇总了C#中ODataQueryContext类的典型用法代码示例。如果您正苦于以下问题:C# ODataQueryContext类的具体用法?C# ODataQueryContext怎么用?C# ODataQueryContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataQueryContext类属于命名空间,在下文中一共展示了ODataQueryContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectExpandQueryOption
/// <summary>
/// Initializes a new instance of the <see cref="SelectExpandQueryOption"/> class.
/// </summary>
/// <param name="select">The $select query parameter value.</param>
/// <param name="expand">The $expand query parameter value.</param>
/// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
/// <param name="queryOptionParser">The <see cref="ODataQueryOptionParser"/> which is used to parse the query option.</param>
public SelectExpandQueryOption(string select, string expand, ODataQueryContext context,
ODataQueryOptionParser queryOptionParser)
{
if (context == null)
{
throw Error.ArgumentNull("context");
}
if (String.IsNullOrEmpty(select) && String.IsNullOrEmpty(expand))
{
throw Error.Argument(SRResources.SelectExpandEmptyOrNull);
}
if (queryOptionParser == null)
{
throw Error.ArgumentNull("queryOptionParser");
}
IEdmEntityType entityType = context.ElementType as IEdmEntityType;
if (entityType == null)
{
throw Error.Argument("context", SRResources.SelectNonEntity, context.ElementType.ToTraceString());
}
Context = context;
RawSelect = select;
RawExpand = expand;
Validator = new SelectExpandQueryValidator();
_queryOptionParser = queryOptionParser;
}
示例2: ODataQueryOptions
/// <summary>
/// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
/// the <see cref="ODataQueryContext"/>.
/// </summary>
/// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information</param>
/// <param name="request">The incoming request message</param>
public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
{
if (context == null)
{
throw Error.ArgumentNull("context");
}
if (request == null)
{
throw Error.ArgumentNull("request");
}
// remember the context
Context = context;
// Parse the query from request Uri
RawValues = new ODataRawQueryOptions();
IEnumerable<KeyValuePair<string, string>> queryParameters = request.GetQueryNameValuePairs();
foreach (KeyValuePair<string, string> kvp in queryParameters)
{
switch (kvp.Key)
{
case "$filter":
RawValues.Filter = kvp.Value;
ThrowIfEmpty(kvp.Value, "$filter");
Filter = new FilterQueryOption(kvp.Value, context);
break;
case "$orderby":
RawValues.OrderBy = kvp.Value;
ThrowIfEmpty(kvp.Value, "$orderby");
OrderBy = new OrderByQueryOption(kvp.Value, context);
break;
case "$top":
RawValues.Top = kvp.Value;
ThrowIfEmpty(kvp.Value, "$top");
Top = new TopQueryOption(kvp.Value, context);
break;
case "$skip":
RawValues.Skip = kvp.Value;
ThrowIfEmpty(kvp.Value, "$skip");
Skip = new SkipQueryOption(kvp.Value, context);
break;
case "$select":
RawValues.Select = kvp.Value;
break;
case "$inlinecount":
RawValues.InlineCount = kvp.Value;
break;
case "$expand":
RawValues.Expand = kvp.Value;
break;
case "$skiptoken":
RawValues.SkipToken = kvp.Value;
break;
default:
// we don't throw if we can't recognize the query
break;
}
}
}
示例3: Validate_DepthChecks_DollarLevels
public void Validate_DepthChecks_DollarLevels(string expand, int maxExpansionDepth)
{
// Arrange
var validator = new SelectExpandQueryValidator();
var builder = new ODataConventionModelBuilder();
builder.EntitySet<ODataLevelsTest.LevelsEntity>("Entities");
IEdmModel model = builder.GetEdmModel();
var context = new ODataQueryContext(model, typeof(ODataLevelsTest.LevelsEntity));
var selectExpandQueryOption = new SelectExpandQueryOption(null, expand, context);
selectExpandQueryOption.LevelsMaxLiteralExpansionDepth = 1;
// Act & Assert
Assert.Throws<ODataException>(
() => validator.Validate(
selectExpandQueryOption,
new ODataValidationSettings { MaxExpansionDepth = maxExpansionDepth }),
String.Format(
CultureInfo.CurrentCulture,
"The request includes a $expand path which is too deep. The maximum depth allowed is {0}. " +
"To increase the limit, set the 'MaxExpansionDepth' property on EnableQueryAttribute or ODataValidationSettings.",
maxExpansionDepth));
Assert.DoesNotThrow(
() => validator.Validate(
selectExpandQueryOption,
new ODataValidationSettings { MaxExpansionDepth = maxExpansionDepth + 1 }));
}
示例4: ODataQueryOptions
/// <summary>
/// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
/// the <see cref="ODataQueryContext"/>.
/// </summary>
/// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
/// <param name="request">The incoming request message.</param>
public ODataQueryOptions(ODataQueryContext context, HttpRequest request)
{
if (context == null)
{
throw Error.ArgumentNull("context");
}
if (request == null)
{
throw Error.ArgumentNull("request");
}
_assemblyProvider = request.AssemblyProvider();
Context = context;
Request = request;
RawValues = new ODataRawQueryOptions();
var queryOptionDict = request.Query.ToDictionary(p => p.Key, p => p.Value.FirstOrDefault());
_queryOptionParser = new ODataQueryOptionParser(
context.Model,
context.ElementType,
context.NavigationSource,
queryOptionDict);
BuildQueryOptions(queryOptionDict);
}
示例5: Constructor_TakingClrType_WithPrimitiveTypes
public void Constructor_TakingClrType_WithPrimitiveTypes(Type type)
{
// Arrange & Act
ODataQueryContext context = new ODataQueryContext(EdmCoreModel.Instance, type);
// Assert
Assert.True(context.ElementClrType == type);
}
示例6: Value_Returns_ParsedSkipValue
public void Value_Returns_ParsedSkipValue(string skipValue, int expectedValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer));
var skip = new SkipQueryOption(skipValue, context);
Assert.Equal(expectedValue, skip.Value);
}
示例7: ODataQueryValidatorTest
public ODataQueryValidatorTest()
{
_validator = new ODataQueryValidator();
_builder = new ODataConventionModelBuilder();
_builder.EntitySet<QueryCompositionCustomer>("Customer");
_model = _builder.GetEdmModel();
_context = new ODataQueryContext(_model, typeof(QueryCompositionCustomer));
}
示例8: 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;
}
示例9: Ctor_ThrowsArgument_IfContextIsNotForAnEntityType
public void Ctor_ThrowsArgument_IfContextIsNotForAnEntityType()
{
ODataQueryContext context = new ODataQueryContext(_model.Model, typeof(int));
Assert.ThrowsArgument(
() => new SelectExpandQueryOption(select: "Name", expand: "Name", context: context),
"context",
"The type 'Edm.Int32' is not an entity type. Only entity types support $select and $expand.");
}
示例10: CanConstructValidFilterQuery
public void CanConstructValidFilterQuery(string orderbyValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer));
var orderby = new OrderByQueryOption(orderbyValue, context);
Assert.Same(context, orderby.Context);
Assert.Equal(orderbyValue, orderby.RawValue);
}
示例11: ApplyInValidOrderbyQueryThrows
public void ApplyInValidOrderbyQueryThrows(string orderbyValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer));
var orderby = new OrderByQueryOption(orderbyValue, context);
Assert.Throws<ODataException>(() =>
orderby.ApplyTo(ODataQueryOptionTest.Customers));
}
示例12: CanConstructValidFilterQuery
public void CanConstructValidFilterQuery(string filterValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer), "Customers");
var filter = new FilterQueryOption(filterValue, context);
Assert.Same(context, filter.Context);
Assert.Equal(filterValue, filter.RawValue);
}
示例13: CanConstructValidFilterQuery
public void CanConstructValidFilterQuery(string skipValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer));
var skip = new SkipQueryOption(skipValue, context);
Assert.Same(context, skip.Context);
Assert.Equal(skipValue, skip.RawValue);
}
示例14: ApplyInValidSkipQueryThrows
public void ApplyInValidSkipQueryThrows(string skipValue)
{
var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
var context = new ODataQueryContext(model, typeof(Customer));
var skip = new SkipQueryOption(skipValue, context);
Assert.Throws<ODataException>(() =>
skip.ApplyTo(ODataQueryOptionTest.Customers));
}
示例15: Ctor_ThrowsArgument_IfBothSelectAndExpandAreNull
public void Ctor_ThrowsArgument_IfBothSelectAndExpandAreNull()
{
_model.Model.SetAnnotationValue<ClrTypeAnnotation>(_model.Customer, new ClrTypeAnnotation(typeof(Customer)));
ODataQueryContext context = new ODataQueryContext(_model.Model, typeof(Customer));
Assert.Throws<ArgumentException>(
() => new SelectExpandQueryOption(select: null, expand: null, context: context),
"'select' and 'expand' cannot be both null or empty.");
}