Reputation: 351
Is it possible to achieve the below routes using the asp.net core 2, web api, odata v4.
By using the attribute routing, declaring functions and customizing routes?
Upvotes: 0
Views: 4352
Reputation: 1
I was also able to achieve it using attribute routing alone too.
app.UseMvc(b =>
{
b.MapODataServiceRoute("odata", "api/v1", GetEdmModel());
});
In the controller:
using Microsoft.AspNet.OData.Routing;
[EnableQuery]
[ODataRoute("content/{contentId}")]
public IActionResult Get(string contentId)
Upvotes: 0
Reputation: 351
After long experiment using attribute routing, functions and actions, the above can be achieved using the OData functions.
Below is the code for it.
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<Product>("Product");
builder.EntityType<Product>().Function("Users").Returns<Users>();
builder.EntityType<Product>().Function("Companies").Returns<Companies>();
app.UseMvc(routebuilder =>
{
routebuilder.MapODataServiceRoute( "OData", "odata", GetEdmModel());
routebuilder.EnableDependencyInjection();
}
Refer the below for more understanding.
Upvotes: 1