I'm having trouble getting OData to work in a new .NET Core WebAPI solution (.NET 5.0).
I am getting data back via the standard "/api/entity" and using a custom filter, but I'd much prefer using the OData built-in $select, $filter, $count, $metadata, etc. features.
I've added the nuget package for Microsoft.AspNetCore.OData v7.5.8, and added the following to my Startup.cs:
ConfigureServices()...
services.AddOData();
Configure()...
endpoints.MapODataRoute("odata", "odata", GetEdmModel()).Select().Filter().Expand().Count();
And the EDM Model method:
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new();
builder.EntitySet<Event>("Events");
return builder.GetEdmModel();
}
Everything compiles, and if I hit [rooturl]/odata
, I see my entity, so I see it's basically working (I think).
However if I go to: [rooturl]/odata/events(1)
I get page not found... however if I use the default [rooturl]/api/events/1
route, it works perfectly.
This is my first .NET Core WebAPI, after building countless .NET Standard WebForms, WCF, MVC, and WebAPI solutions. I am sure I'm just missing something simple... but I cannot figure out what.
I would like to be able to use OData like this:
[rooturl]/odata/Events?$top=10
[rooturl]/odata/Events?$filter=name eq "foo"
[rooturl]/odata/Events?$select=id,name,status
In .NET Standard MVC, OData functionality was available right off the bat. How do I get that with .NET Core?
Anyone have suggestions on what to add to get this wired up properly?
Many thanks in advance.