I have been writing WebApi with OData v4 these days. While it is really fast, and convenient, I experienced a few pitfalls which costs me several hours.
URL Sensitivity ๐
The path segment etc. are case sensitive by default. Thus, you would
probably receive an HTTP 404 when GET ~/api/customers instead of~/api/Customers.
String Parameter Issue ๐
Assuming that I have a bound function GetCustomerX for the entity
type Customer, and it is indexed with a string identifier.
public IHttpActionResult GetCustomerX(string key)
When calling into this function with string 'foo', the parameterkey will be bounded to a single quoted string 'foo'. To escape
from the single quote, you need to decorate the key parameter withFromODataUri attribute.
public IHttpActionResult GetCustomerX([FromODataUri] string key)
404 on Function Routing ๐
This issue almost drove me crazy. I had a bound function, but always
got a 404 error, by all means. And it turns out that, I missed the
following configuration in my web.config.
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
I found this solution fromstackoverflow.
Further Readings ๐
The issues above in fact have all been captured inOData Web API document. Make sure you read it before building WebApi with OData in production code.