ASP.NET OData Function Parameter Parsing

It's the simple things in life that get you.

In this case, I had a ASP.NET Web API OData service that had a function.

[ODataRoute("Default.MyFunctionName(Param1={param1},Param2={param2})")]
public IHttpActionResult MyFunctionName(string param1, EnumType param2)
{
    return Ok(repository.MyFunctionName(param1, param2));
}

I thought everything was working well, until I started getting weird results from my repository layer. I called this function:

https://myservice.example.com/odata/Entity1/Default.MyFunctionName(Param1='123abc',Param2=EmumType'Value')

I was getting the value '123abc' in the param1 variable instead of 123abc. It was including the single quotes! No wonder nothing was matching on param1!

Some examples pointed me in the right direction. I realized that the issue was that the code was parsing out the URL as a Web API URI and not an OData one. The [FromODataUri] attribute on my parameter name fixed everything right up.

[ODataRoute("Default.MyFunctionName(Param1={param1},Param2={param2})")]
public IHttpActionResult MyFunctionName([FromODataUri] string param1, EnumType param2)
{
    return Ok(repository.MyFunctionName(param1, param2));
}

From what I can tell this issue only appears to affect strings and how they're parsed. Integers will work just fine without it (though you should probably add the attribute to those parameters as well).