OData Wonderror
Gosh, waste about 4 hours to get this simple problem done !
The problem was to get this web API /odata/Staff('0001') to return data instead of 404.
After stumbled so many resource that lead to routing convention problem, nothing worked !
I then suspect the problem not caused by something wrong in routing convention but because of I use ViewModel instead exposing my Entity.
A look into my ODataConventionModelBuilder I found an entity that directly exposed without ViewModel. Query against this entity in OData with key return a valid data. This prove my suspicion.
With this new clue I then googled : "odataconventionmodelbuilder entityset aliasing"
and voila it directly brought me to this SO : How do I map an OData query against a DTO to an EF entity? with a promising answer !
The Solution
Change code from builder.EntitySet(Of StaffView)("Staff") To builder.ModelAliasingEnabled = True builder.EntitySet(Of StaffView)("Staff").EntityType.Name = "Staff"
Imagine 4 hours just to find this solution.
Well that the cost of learning things by yourself without a mentor.







