Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
87 changes: 73 additions & 14 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,20 +1102,6 @@
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateTime; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsDateOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.DateOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a DateOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeOnly(System.Type)">
<summary>
Determine if a type is a <see cref="T:System.TimeOnly"/>.
</summary>
<param name="clrType">The type to test.</param>
<returns>True if the type is a TimeOnly; false otherwise.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Common.TypeHelper.IsTimeSpan(System.Type)">
<summary>
Determine if a type is a TimeSpan.
Expand Down Expand Up @@ -13000,6 +12986,14 @@
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext)">
<inheritdoc />
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmEntitySet,Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<summary>
Tests whether to apply $count on the <see cref="T:Microsoft.OData.Edm.IEdmEntitySet"/>.
</summary>
<param name="entitySet">The entity set to test.</param>
<param name="routeOptions">The route options.</param>
<returns>True/false to identify whether to apply $count.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Routing.Conventions.FunctionRoutingConvention">
<summary>
The convention for <see cref="T:Microsoft.OData.Edm.IEdmFunction"/>.
Expand Down Expand Up @@ -13108,6 +13102,16 @@
<param name="declaring">The declaring name (out).</param>
<returns>The http method name or null.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.NavigationRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmNavigationProperty,System.String,Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<summary>
OData spec: To request only the number of items of a collection of entities or items of a collection-valued property,
the client issues a GET request with /$count appended to the resource path of the collection.
</summary>
<param name="edmProperty">The property to test.</param>
<param name="method">The http method.</param>
<param name="routeOptions">The route options.</param>
<returns>True/false to identify whether to apply $count.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext">
<summary>
A context object for <see cref="T:Microsoft.AspNetCore.OData.Routing.Conventions.IODataControllerActionConvention"/>.
Expand Down Expand Up @@ -13280,6 +13284,35 @@
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext)">
<inheritdoc />
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApply(Microsoft.OData.Edm.IEdmProperty,System.String,Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<summary>
Tests whether to apply routings for the given property.
</summary>
<param name="edmProperty">The property to test.</param>
<param name="method">The http method.</param>
<param name="routeOptions">The route options.</param>
<returns>True/false to identify whether to apply routings for the given property.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApplyDollarValue(Microsoft.OData.Edm.IEdmProperty,System.String,Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<summary>
OData spec: To retrieve the raw value of a primitive type property, the client sends a GET request to the property value URL.
So, let's apply $value for the "Get" and non-collection primitive property
</summary>
<param name="edmProperty">The property to test.</param>
<param name="method">The http method.</param>
<param name="routeOptions">The route options.</param>
<returns>True/false to identify whether to apply $value.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmProperty,System.String,Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<summary>
OData spec: To request only the number of items of a collection of entities or items of a collection-valued property,
the client issues a GET request with /$count appended to the resource path of the collection.
</summary>
<param name="edmProperty">The property to test.</param>
<param name="method">The http method.</param>
<param name="routeOptions">The route options.</param>
<returns>True/false to identify whether to apply $count.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Routing.Conventions.RefRoutingConvention">
<summary>
An implementation of <see cref="T:Microsoft.AspNetCore.OData.Routing.Conventions.IODataControllerActionConvention"/> that handles entity reference manipulations.
Expand Down Expand Up @@ -13656,6 +13689,16 @@
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Routing.ODataRouteOptions" /> class.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarCountRouting">
<summary>
Gets/sets a value indicating whether to enable $count in conventional routing.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarValueRouting">
<summary>
Gets/sets a value indicating whether to enable $value in conventional routing.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableActionNameCaseInsensitive">
<summary>
Gets/sets a value indicating whether to enable case insensitive for the action name in conventional routing.
Expand Down Expand Up @@ -14933,3 +14976,19 @@
</member>
</members>
</doc>
ummary>
<param name="segment">The value segment.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.Segment">
<summary>
Gets the value segment.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.GetTemplates(Microsoft.AspNetCore.OData.Routing.ODataRouteOptions)">
<inheritdoc />
</member>
<member name="M:Microsoft.AspNetCore.OData.Routing.Template.ValueSegmentTemplate.TryTranslate(Microsoft.AspNetCore.OData.Routing.Template.ODataTemplateTranslateContext)">
<inheritdoc />
</member>
</members>
</doc>
11 changes: 11 additions & 0 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,12 @@ Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableActionNameCaseInsensi
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableActionNameCaseInsensitive.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableControllerNameCaseInsensitive.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableControllerNameCaseInsensitive.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableConventionalRoutingIfODataRoutingPresent.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableConventionalRoutingIfODataRoutingPresent.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarCountRouting.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarCountRouting.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarValueRouting.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableDollarValueRouting.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableKeyAsSegment.get -> bool
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableKeyAsSegment.set -> void
Microsoft.AspNetCore.OData.Routing.ODataRouteOptions.EnableKeyInParenthesis.get -> bool
Expand Down Expand Up @@ -1978,19 +1984,24 @@ virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntityRoutingConvention.A
virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntityRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmEntitySet entitySet, Microsoft.AspNetCore.OData.Routing.ODataRouteOptions routeOptions) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.EntitySetRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.MetadataRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.MetadataRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.MetadataRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.NavigationRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.NavigationRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.NavigationRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmNavigationProperty edmProperty, string method, Microsoft.AspNetCore.OData.Routing.ODataRouteOptions routeOptions) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.NavigationRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.OperationImportRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.OperationImportRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.OperationImportRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.OperationRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.AppliesToAction(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApply(Microsoft.OData.Edm.IEdmProperty edmProperty, string method, Microsoft.AspNetCore.OData.Routing.ODataRouteOptions routeOptions) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApplyDollarCount(Microsoft.OData.Edm.IEdmProperty edmProperty, string method, Microsoft.AspNetCore.OData.Routing.ODataRouteOptions routeOptions) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.CanApplyDollarValue(Microsoft.OData.Edm.IEdmProperty edmProperty, string method, Microsoft.AspNetCore.OData.Routing.ODataRouteOptions routeOptions) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.PropertyRoutingConvention.Order.get -> int
virtual Microsoft.AspNetCore.OData.Routing.Conventions.RefRoutingConvention.AppliesToController(Microsoft.AspNetCore.OData.Routing.Conventions.ODataControllerActionContext context) -> bool
virtual Microsoft.AspNetCore.OData.Routing.Conventions.RefRoutingConvention.Order.get -> int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public virtual bool AppliesToAction(ODataControllerActionContext context)
return ProcessEntitySetAction(actionPrefix, entitySet, castType, context, action);
}

private static bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet, IEdmStructuredType castType,
private bool ProcessEntitySetAction(string actionName, IEdmEntitySet entitySet, IEdmStructuredType castType,
ODataControllerActionContext context, ActionModel action)
{
StringComparison actionNameComparison = context.Options?.RouteOptions?.EnableActionNameCaseInsensitive == true ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
Expand Down Expand Up @@ -126,21 +126,25 @@ private static bool ProcessEntitySetAction(string actionName, IEdmEntitySet enti
ODataPathTemplate template = new ODataPathTemplate(segments);
action.AddSelector("Get", context.Prefix, context.Model, template, context.Options?.RouteOptions);

// GET ~/Customers/$count or GET ~/Customers/Ns.VipCustomer/$count
segments = new List<ODataSegmentTemplate>
if (CanApplyDollarCount(entitySet, context.Options?.RouteOptions))
{
new EntitySetSegmentTemplate(entitySet)
};
// GET ~/Customers/$count or GET ~/Customers/Ns.VipCustomer/$count
segments = new List<ODataSegmentTemplate>
{
new EntitySetSegmentTemplate(entitySet)
};

if (castType != null)
{
segments.Add(new CastSegmentTemplate(castCollectionType, entityCollectionType, entitySet));
}
if (castType != null)
{
segments.Add(new CastSegmentTemplate(castCollectionType, entityCollectionType, entitySet));
}

segments.Add(CountSegmentTemplate.Instance);
segments.Add(CountSegmentTemplate.Instance);

template = new ODataPathTemplate(segments);
action.AddSelector("Get", context.Prefix, context.Model, template, context.Options?.RouteOptions);
}

template = new ODataPathTemplate(segments);
action.AddSelector("Get", context.Prefix, context.Model, template, context.Options?.RouteOptions);
return true;
}
else if (actionName.Equals("Post", actionNameComparison) || actionName.Equals($"Post{entitySet.EntityType().Name}", actionNameComparison))
Expand Down Expand Up @@ -183,5 +187,14 @@ private static bool ProcessEntitySetAction(string actionName, IEdmEntitySet enti

return false;
}

/// <summary>
/// Tests whether to apply $count on the <see cref="IEdmEntitySet"/>.
/// </summary>
/// <param name="entitySet">The entity set to test.</param>
/// <param name="routeOptions">The route options.</param>
/// <returns>True/false to identify whether to apply $count.</returns>
protected virtual bool CanApplyDollarCount(IEdmEntitySet entitySet, ODataRouteOptions routeOptions)
=> routeOptions != null ? routeOptions.EnableDollarCountRouting : false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public virtual bool AppliesToAction(ODataControllerActionContext context)

AddSelector(method, context, action, navigationSource, declared, declaringEntityType, navigationProperty, hasKeyParameter, false);

if (CanApplyDollarCount(navigationProperty, method))
if (CanApplyDollarCount(navigationProperty, method, context.Options?.RouteOptions))
{
AddSelector(method, context, action, navigationSource, declared, declaringEntityType, navigationProperty, hasKeyParameter, true);
}
Expand Down Expand Up @@ -244,11 +244,25 @@ internal static string SplitActionName(string actionName, out string property, o
return method;
}

// OData spec: To request only the number of items of a collection of entities or items of a collection-valued property,
// the client issues a GET request with /$count appended to the resource path of the collection.
private static bool CanApplyDollarCount(IEdmNavigationProperty edmProperty, string method)
/// <summary>
/// OData spec: To request only the number of items of a collection of entities or items of a collection-valued property,
/// the client issues a GET request with /$count appended to the resource path of the collection.
/// </summary>
/// <param name="edmProperty">The property to test.</param>
/// <param name="method">The http method.</param>
/// <param name="routeOptions">The route options.</param>
/// <returns>True/false to identify whether to apply $count.</returns>
protected virtual bool CanApplyDollarCount(IEdmNavigationProperty edmProperty, string method, ODataRouteOptions routeOptions)
{
Contract.Assert(edmProperty != null);
if(edmProperty == null)
{
throw Error.ArgumentNull(nameof(edmProperty));
}

if (routeOptions != null && !routeOptions.EnableDollarCountRouting)
{
return false;
}

return method == "Get" && edmProperty.Type.IsCollection();
}
Expand Down
Loading