I have a custom function declared in my EdmModel:
var getWebMenu = builder.Function("GetWebMenu");
getWebMenu.Parameter<Guid>("SiteId");
getWebMenu.Parameter<Guid>("LanguageId");
getWebMenu.Parameter<string>("MenuName");
getWebMenu.Parameter<int>("MenuIndex");
When I call this via HTTP it works just fine. However, the underlying data type for MenuIndex is a short
(int16
) and when I convert the code back to a short
getWebMenu.Parameter<short>("MenuIndex");
(and, obviously, flow that change through my code) the HTTP call fails with a 404.0 - Not found
.
The HTTP call looks like this in both cases:
http://localhost:19215/GetWebMenu(SiteId=ac2453bd-f2dd-e411-8159-984be10349a2,
LanguageId=ac2453bd-f2dd-e411-8159-984be10349a2,
MenuName='Main Menu',MenuIndex=0)?$expand=webMenuItems
The http://localhost:19215/$metadata
looks just fine when the param is declared as a short
:
<Function Name="GetWebMenu">
<Parameter Name="SiteId" Type="Edm.Guid" Nullable="false"/>
<Parameter Name="LanguageId" Type="Edm.Guid" Nullable="false"/>
<Parameter Name="MenuName" Type="Edm.String" Unicode="false"/>
<Parameter Name="MenuIndex" Type="Edm.Int16" Nullable="false"/>
<ReturnType Type="data.models.WebMenu"/>
</Function>
More Info
While writing this question I have double checked a couple of things and I have found that my assumption to "obviously" flow that change through my code seems to have made an ass out of at least me. When it was failing, the Controller function signature looked like this:
[ODataRoute("GetWebMenu(SiteId={siteId}, LanguageId={languageId}, MenuName={menuName},
MenuIndex={menuIndex})")]
[SingleResultEnableQuery]
public SingleResult<WebMenu> GetWebMenu([FromODataUri] Guid siteId,
[FromODataUri] Guid languageId, [FromODataUri] string menuName,
[FromODataUri] short menuIndex)
See the short
datatype for menuIndex
? I was changing that to int
when I changed the getWebMenu.Parameter<short>("MenuIndex");
datatype to int
and vice versa.
Answer?
However; if I keep the getWebMenu.Parameter<int>("MenuIndex");
as an int
and keep the rest of my code as a short
the HTTP calls work just fine.
Question!
Since Edm.Int16 is a supported type and I want my users to know an Edm.Int16 is required, please can someone tell me how I can declare a short
in my custom function declaration on the EdmModel?
It's confirmed as a bug in the URL parser in the ODataLib by our engineers and a GitHub issue is created for it: https://github.com/OData/odata.net/issues/154. Please monitor the fix status using it.