Versioning OData controllers
It is good practice to plan for future versions of your OData models that might have different schemas and behavior.
To maintain backward compatibility, you can use OData URL prefixes to specify a version number:
- In the
Northwind.OData.Service
project, inProgram.cs
, in the services configuration section, after adding the two OData models forcatalog
andorders
, add a third OData model that has a version number and uses the sameGetEdmModelForCatalog
method, as shown highlighted in the following code:.AddRouteComponents(routePrefix: "catalog", model: GetEdmModelForCatalog()) .AddRouteComponents(routePrefix: "ordersystem", model: GetEdmModelForOrderSystem()) .AddRouteComponents(routePrefix: "catalog/v{version}", model: GetEdmModelForCatalog())
- In
ProductsController.cs
, modify theGet
methods to add astring
parameter namedversion
that defaults to"1"
, and use it to change...