When I try to use a third level segment with [ODataRoutePrefix]
attribute it throws an error like this:
The path template '[TEMPLATE]' on the action 'Get' in controller 'CONTROLLER-NAME' is not a valid OData path template. Found an unresolved path segment '[LAST-SEGMENT]' in the OData path template '[TEMPLATE]'.
[ODataRoutePrefix("lawsuits/{parentId}/depositsGuarantees")]
[ODataRoutePrefix("lawsuits/{parentId}/depositsGuarantees/{subResourceId}/customFields")]
config.EnsureInitialized()
):
The path template 'lawsuits/{parentId}/depositsGuarantees/{subResourceId}/customFields' on the action 'Get' in controller 'LawsuitDepositGuaranteeCustomFields' is not a valid OData path template. Found an unresolved path segment 'customFields' in the OData path template 'lawsuits/{parentId}/depositsGuarantees/{subResourceId}/customFields'.public IHttpActionResult Get(int parentId, int subResourceId)
{
// [...]
}
[ODataRoutePrefix("lawsuits/{parentId}/customFields")]
, which means there's a model registered on OData for the "customFields" segment.OData WebApi lib 6.0.0
I've found what was the problem...
The model for the depositsGuarantees
segment was missing a collection property of the model registered for the customFields
segment. In practice this property was missing :
public IEnumerable<CustomFieldModel> CustomFields { get; set; }
I still wonder if I should really use lawsuits/{parentId}/depositsGuarantees/{subResourceId}/customFields
or just depositsGuarantees/{parentId}/customFields
(even though depositsGuarantees
is also a sub-resource), but this is more a conceptual discussion.