Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Microsoft.AspNetCore.OData/Edm/EdmHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public static IEnumerable<IEdmEntityType> GetAllDerivedEntityTypes(IEdmEntityTyp
}

public static bool IsTopLimitExceeded(IEdmProperty property, IEdmStructuredType structuredType,
IEdmModel edmModel, int top, DefaultQuerySettings defaultQuerySettings, out int maxTop)
IEdmModel edmModel, int top, DefaultQueryConfigurations defaultQueryConfs, out int maxTop)
Comment thread
xuzhg marked this conversation as resolved.
Outdated
{
maxTop = 0;
ModelBoundQuerySettings querySettings = edmModel.GetModelBoundQuerySettings(property, structuredType, defaultQuerySettings);
ModelBoundQuerySettings querySettings = edmModel.GetModelBoundQuerySettings(property, structuredType, defaultQueryConfs);
if (querySettings != null && top > querySettings.MaxTop)
{
maxTop = querySettings.MaxTop.Value;
Expand Down Expand Up @@ -339,27 +339,27 @@ public static ModelBoundQuerySettings GetModelBoundQuerySettingsOrNull(this IEdm
}

public static ModelBoundQuerySettings GetModelBoundQuerySettings(this IEdmModel edmModel, IEdmProperty property,
IEdmStructuredType structuredType, DefaultQuerySettings defaultQuerySettings = null)
IEdmStructuredType structuredType, DefaultQueryConfigurations defaultQueryConfs = null)
{
if (edmModel == null)
{
throw Error.ArgumentNull(nameof(edmModel));
}

ModelBoundQuerySettings querySettings = edmModel.GetModelBoundQuerySettings(structuredType, defaultQuerySettings);
ModelBoundQuerySettings querySettings = edmModel.GetModelBoundQuerySettings(structuredType, defaultQueryConfs);
if (property == null)
{
return querySettings;
}
else
{
// Settings on property is higher priority than the ones on type.
ModelBoundQuerySettings propertyQuerySettings = edmModel.GetModelBoundQuerySettings(property, defaultQuerySettings);
ModelBoundQuerySettings propertyQuerySettings = edmModel.GetModelBoundQuerySettings(property, defaultQueryConfs);
return GetMergedPropertyQuerySettings(propertyQuerySettings, querySettings);
}
}

private static ModelBoundQuerySettings GetModelBoundQuerySettings<T>(this IEdmModel edmModel, T key, DefaultQuerySettings defaultQuerySettings = null)
private static ModelBoundQuerySettings GetModelBoundQuerySettings<T>(this IEdmModel edmModel, T key, DefaultQueryConfigurations defaultQueryConfs = null)
where T : IEdmElement
{
if (key == null)
Expand All @@ -372,10 +372,10 @@ private static ModelBoundQuerySettings GetModelBoundQuerySettings<T>(this IEdmMo
if (querySettings == null)
{
querySettings = new ModelBoundQuerySettings();
if (defaultQuerySettings != null &&
(!defaultQuerySettings.MaxTop.HasValue || defaultQuerySettings.MaxTop > 0))
if (defaultQueryConfs != null &&
(!defaultQueryConfs.MaxTop.HasValue || defaultQueryConfs.MaxTop > 0))
{
querySettings.MaxTop = defaultQuerySettings.MaxTop;
querySettings.MaxTop = defaultQueryConfs.MaxTop;
}
}

Expand Down
51 changes: 47 additions & 4 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6275,9 +6275,9 @@
Gets or sets whether or not the OData system query options should be prefixed with '$'.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.ODataOptions.QuerySettings">
<member name="P:Microsoft.AspNetCore.OData.ODataOptions.QueryConfigurations">
<summary>
Gets the query setting.
Gets the query configurations.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.ODataOptions.BuildRouteContainer(Microsoft.OData.Edm.IEdmModel,Microsoft.OData.ODataVersion,System.Action{Microsoft.Extensions.DependencyInjection.IServiceCollection})">
Expand Down Expand Up @@ -8012,6 +8012,49 @@
<member name="M:Microsoft.AspNetCore.OData.Query.DefaultODataQueryRequestParser.ParseAsync(Microsoft.AspNetCore.Http.HttpRequest)">
<inheritdoc/>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations">
<summary>
This class describes the default settings to use during query composition.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableExpand">
<summary>
Gets or sets a value indicating whether navigation property can be expanded.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSelect">
<summary>
Gets or sets a value indicating whether property can be selected.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableCount">
<summary>
Gets or sets a value indicating whether entity set and property can apply $count.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableOrderBy">
<summary>
Gets or sets a value indicating whether property can apply $orderby.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableFilter">
<summary>
Gets or sets a value indicating whether property can apply $filter.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.MaxTop">
<summary>
Gets or sets the max value of $top that a client can request.
</summary>
<value>
The max value of $top that a client can request, or <c>null</c> if there is no limit.
</value>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSkipToken">
<summary>
Gets or sets a value indicating whether the service will use skiptoken or not.
</summary>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.EnableQueryAttribute">
<summary>
This partial class defines the configuration on <see cref="T:Microsoft.AspNetCore.OData.Query.EnableQueryAttribute"/>.
Expand Down Expand Up @@ -9776,9 +9819,9 @@
<param name="elementType">The EDM type of the element of the collection being queried.</param>
<param name="path">The parsed <see cref="T:Microsoft.OData.UriParser.ODataPath"/>.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQuerySettings">
<member name="P:Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQueryConfigurations">
<summary>
Gets the given <see cref="P:Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQuerySettings"/>.
Gets the given <see cref="P:Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQueryConfigurations"/>.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.ODataQueryContext.Model">
Expand Down
35 changes: 18 additions & 17 deletions src/Microsoft.AspNetCore.OData/ODataOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Diagnostics.Contracts;
using Microsoft.AspNetCore.OData.Abstracts;
using Microsoft.AspNetCore.OData.Batch;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing;
using Microsoft.AspNetCore.OData.Routing.Conventions;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -195,12 +196,12 @@ public IServiceProvider GetRouteServices(string routePrefix)
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions EnableQueryFeatures(int? maxTopValue = null)
{
QuerySettings.EnableExpand = true;
QuerySettings.EnableSelect = true;
QuerySettings.EnableFilter = true;
QuerySettings.EnableOrderBy = true;
QuerySettings.EnableCount = true;
QuerySettings.EnableSkipToken = true;
QueryConfigurations.EnableExpand = true;
QueryConfigurations.EnableSelect = true;
QueryConfigurations.EnableFilter = true;
QueryConfigurations.EnableOrderBy = true;
QueryConfigurations.EnableCount = true;
QueryConfigurations.EnableSkipToken = true;
SetMaxTop(maxTopValue);
return this;
}
Expand All @@ -211,7 +212,7 @@ public ODataOptions EnableQueryFeatures(int? maxTopValue = null)
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions Expand()
{
QuerySettings.EnableExpand = true;
QueryConfigurations.EnableExpand = true;
return this;
}

Expand All @@ -221,7 +222,7 @@ public ODataOptions Expand()
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions Select()
{
QuerySettings.EnableSelect = true;
QueryConfigurations.EnableSelect = true;
return this;
}

Expand All @@ -231,7 +232,7 @@ public ODataOptions Select()
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions Filter()
{
QuerySettings.EnableFilter = true;
QueryConfigurations.EnableFilter = true;
return this;
}

Expand All @@ -241,7 +242,7 @@ public ODataOptions Filter()
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions OrderBy()
{
QuerySettings.EnableOrderBy = true;
QueryConfigurations.EnableOrderBy = true;
return this;
}

Expand All @@ -251,7 +252,7 @@ public ODataOptions OrderBy()
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions Count()
{
QuerySettings.EnableCount = true;
QueryConfigurations.EnableCount = true;
return this;
}

Expand All @@ -261,7 +262,7 @@ public ODataOptions Count()
/// <returns>The current <see cref="ODataOptions"/> instance to enable fluent configuration.</returns>
public ODataOptions SkipToken()
{
QuerySettings.EnableSkipToken = true;
QueryConfigurations.EnableSkipToken = true;
return this;
}

Expand All @@ -277,7 +278,7 @@ public ODataOptions SetMaxTop(int? maxTopValue)
throw Error.ArgumentMustBeGreaterThanOrEqualTo(nameof(maxTopValue), maxTopValue, 0);
}

QuerySettings.MaxTop = maxTopValue;
QueryConfigurations.MaxTop = maxTopValue;
return this;
}

Expand All @@ -287,9 +288,9 @@ public ODataOptions SetMaxTop(int? maxTopValue)
public bool EnableNoDollarQueryOptions { get; set; } = true;

/// <summary>
/// Gets the query setting.
/// Gets the query configurations.
/// </summary>
public DefaultQuerySettings QuerySettings { get; } = new DefaultQuerySettings();
public DefaultQueryConfigurations QueryConfigurations { get; } = new DefaultQueryConfigurations();

#endregion

Expand All @@ -310,8 +311,8 @@ private IServiceProvider BuildRouteContainer(IEdmModel model, ODataVersion versi
// Inject the core odata services.
builder.AddDefaultODataServices(version);

// Inject the default query setting from this options.
builder.Services.AddSingleton(sp => QuerySettings);
// Inject the default query configuration from this options.
builder.Services.AddSingleton(sp => this.QueryConfigurations);

// Inject the default Web API OData services.
builder.AddDefaultWebApiServices();
Expand Down
20 changes: 18 additions & 2 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ Microsoft.AspNetCore.OData.ODataOptions.Filter() -> Microsoft.AspNetCore.OData.O
Microsoft.AspNetCore.OData.ODataOptions.GetRouteServices(string routePrefix) -> System.IServiceProvider
Microsoft.AspNetCore.OData.ODataOptions.ODataOptions() -> void
Microsoft.AspNetCore.OData.ODataOptions.OrderBy() -> Microsoft.AspNetCore.OData.ODataOptions
Microsoft.AspNetCore.OData.ODataOptions.QuerySettings.get -> Microsoft.OData.ModelBuilder.Config.DefaultQuerySettings
Microsoft.AspNetCore.OData.ODataOptions.QueryConfigurations.get -> Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations
Microsoft.AspNetCore.OData.ODataOptions.RouteComponents.get -> System.Collections.Generic.IDictionary<string, (Microsoft.OData.Edm.IEdmModel EdmModel, System.IServiceProvider ServiceProvider)>
Microsoft.AspNetCore.OData.ODataOptions.RouteOptions.get -> Microsoft.AspNetCore.OData.Routing.ODataRouteOptions
Microsoft.AspNetCore.OData.ODataOptions.Select() -> Microsoft.AspNetCore.OData.ODataOptions
Expand Down Expand Up @@ -812,6 +812,22 @@ Microsoft.AspNetCore.OData.Query.DefaultODataQueryRequestParser
Microsoft.AspNetCore.OData.Query.DefaultODataQueryRequestParser.CanParse(Microsoft.AspNetCore.Http.HttpRequest request) -> bool
Microsoft.AspNetCore.OData.Query.DefaultODataQueryRequestParser.DefaultODataQueryRequestParser() -> void
Microsoft.AspNetCore.OData.Query.DefaultODataQueryRequestParser.ParseAsync(Microsoft.AspNetCore.Http.HttpRequest request) -> System.Threading.Tasks.Task<string>
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.DefaultQueryConfigurations() -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableCount.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableCount.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableExpand.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableExpand.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableFilter.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableFilter.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableOrderBy.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableOrderBy.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSelect.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSelect.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSkipToken.get -> bool
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.EnableSkipToken.set -> void
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.MaxTop.get -> int?
Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations.MaxTop.set -> void
Microsoft.AspNetCore.OData.Query.DefaultSkipTokenHandler
Microsoft.AspNetCore.OData.Query.DefaultSkipTokenHandler.DefaultSkipTokenHandler() -> void
Microsoft.AspNetCore.OData.Query.EnableQueryAttribute
Expand Down Expand Up @@ -935,7 +951,7 @@ Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser
Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser.CanParse(Microsoft.AspNetCore.Http.HttpRequest request) -> bool
Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser.ParseAsync(Microsoft.AspNetCore.Http.HttpRequest request) -> System.Threading.Tasks.Task<string>
Microsoft.AspNetCore.OData.Query.ODataQueryContext
Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQuerySettings.get -> Microsoft.OData.ModelBuilder.Config.DefaultQuerySettings
Microsoft.AspNetCore.OData.Query.ODataQueryContext.DefaultQueryConfigurations.get -> Microsoft.AspNetCore.OData.Query.DefaultQueryConfigurations
Microsoft.AspNetCore.OData.Query.ODataQueryContext.ElementClrType.get -> System.Type
Microsoft.AspNetCore.OData.Query.ODataQueryContext.ElementType.get -> Microsoft.OData.Edm.IEdmType
Microsoft.AspNetCore.OData.Query.ODataQueryContext.Model.get -> Microsoft.OData.Edm.IEdmModel
Expand Down
67 changes: 67 additions & 0 deletions src/Microsoft.AspNetCore.OData/Query/DefaultQueryConfigurations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------------
// <copyright file="DefaultQueryConfigurations.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
//------------------------------------------------------------------------------

namespace Microsoft.AspNetCore.OData.Query
{
/// <summary>
/// This class describes the default settings to use during query composition.
Comment thread
xuzhg marked this conversation as resolved.
Outdated
/// </summary>
public class DefaultQueryConfigurations
{
private int? _maxTop = 0;

/// <summary>
/// Gets or sets a value indicating whether navigation property can be expanded.
/// </summary>
public bool EnableExpand { get; set; }

/// <summary>
/// Gets or sets a value indicating whether property can be selected.
/// </summary>
public bool EnableSelect { get; set; }

/// <summary>
/// Gets or sets a value indicating whether entity set and property can apply $count.
/// </summary>
public bool EnableCount { get; set; }

/// <summary>
/// Gets or sets a value indicating whether property can apply $orderby.
/// </summary>
public bool EnableOrderBy { get; set; }

/// <summary>
/// Gets or sets a value indicating whether property can apply $filter.
/// </summary>
public bool EnableFilter { get; set; }

/// <summary>
/// Gets or sets the max value of $top that a client can request.
/// </summary>
/// <value>
/// The max value of $top that a client can request, or <c>null</c> if there is no limit.
/// </value>
public int? MaxTop
{
get => _maxTop;
set
{
if (value.HasValue && value < 0)
{
throw Error.ArgumentMustBeGreaterThanOrEqualTo("value", value, 0);
}

_maxTop = value;
}
}

/// <summary>
/// Gets or sets a value indicating whether the service will use skiptoken or not.
/// </summary>
public bool EnableSkipToken { get; set; }
}
}
Loading