Reputation: 13840
I have added OData V4 to my Web Api 2 app. registered OData route in WebApiConfig register method before default route:
//defining the routes for our OData service
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "odata",
model: GenerateEdmModel());
private static IEdmModel GenerateEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<Media>("Media");
return builder.GetEdmModel();
}
MediaController.cs
[EnableQuery]
public IQueryable<ApiMedia> GetMedia(ODataQueryOptions<Media> query )
{
*querying and returning media*
}
but when I call localhost:80880/odata/media
returned response says:
The resource cannot be found. Requested URL: /odata/media
calling localhost:80880/odata
returns this:
{
"@odata.context":"http://localhost:80880/odata/$metadata","value":[
{
"name":"Media","kind":"EntitySet","url":"Media"
}
]
}
so whats wrong here? (does it looking for a controller named odata?) I followed the tutorial on http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint
Upvotes: 0
Views: 1547
Reputation: 706
You will quickly find this feature. I was looking for 2 days. Uppercase url request depends on the entityset name
builder.EntitySet<Media>("Media"); // if the changed to "media" will work !
Upvotes: 0
Reputation: 13840
you cant believe but I should type mysite.com/odata/Media not mysite.com/odata/media
Upvotes: 1