locked
ASP.NET Core 3.1 OData with Endpoint Routing and Versioning RRS feed

  • Question

  • User-348859257 posted

    Hi!

    I am creating an ASP.NET Core 3.1 OData project using endpoint routing (it is already supported) and versioning.

    While registering my OData route I have not one but two models (`IEdmModel`), which I get from `VersionedODataModelBuilder`, one for each API version (I have two for now).
    I am registering the endpoint as this:

    endpoints.MapODataRoute("odata", "odata/v{version:apiversion}", models.First());  //or models.First()

    The problem is, I need to have an endpoint for each model, otherwise, the endpoint will only have knowledge of one, and the endpoint also needs to take a parameter for the API version.

    This is working, in a way, but, as I said, the endpoint will always get the same model, which may not be appropriate (different properties or different functions per version, for example).
    In older versions of OData Versioning there was a `MapVersionedODataRoute` extension method which took a collection of models, but it's now gone.

    Any ideas on how to achive this?

    Thanks!

    Monday, June 22, 2020 7:56 PM

All replies

  • User-348859257 posted

    One possible alternative is to have an endpoint for each version:

    endpoints.MapODataRoute("odata", "odata/v1.0", models.ElementAt(0));

    endpoints.MapODataRoute("odata", "odata/v2.0", models.ElementAt(1));

    Bun in this case the endpoint knows nothing about the version, that is, it does not respect the [ApiVersion] attributes on the action methods.

    Wednesday, June 24, 2020 9:49 AM