Based on the DynamicEdmModelCreation project from ODataSamples-master odata examples and following the help received in the question Handle Odata /entityset/key/navigation We now need to expose dynamic Actions and Funcions with parameters. To support unbound function we made in the GetModel Function the following:
var GetSum = new EdmFunction("ns", "GetSum",
new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Double), false),
false, null, true);
GetSum.AddParameter("param1",
new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Double),
false));
GetSum.AddParameter("param2",
new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Double),
false));
model.AddElement(GetSum);
container.AddFunctionImport(GetSum);
and in the SelectAction method we put:
if (odataPath.Segments.Count > 0 &&
odataPath.Segments.Last() is UnboundFunctionPathSegment &&
odataPath.Segments.Last().ToString().Contains("GetSum"))
return "ExecuteFunction";
Finally the controller has
[HttpGet]
[HttpPost]
public IHttpActionResult ExecuteFunction(ODataActionParameters parameters)
{
...
}
Now testing the service:
http://localhost:2900/odata/GetSum(param1=1,param2=2)
Everything works fine except for the parameters, they always enter as null. Is there anything that we are missing to support the parameters?