asp.net-web-api2odataasp.net-web-api-odata

ODataRoutePrefix not working for 3rd level


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]'.

Details

Additional info

public IHttpActionResult Get(int parentId, int subResourceId)
{
    // [...]
}

Assemblies affected

OData WebApi lib 6.0.0


Solution

  • 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.