Implementing versions and data modifications
Now, let’s look at how you can implement some more features, including versioning and enabling data modifications.
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.ODataproject, in theExtensionsfolder, inIServiceCollectionExtensions.cs, after adding the two OData models forcatalogandorders, add a third OData model that has a version number and uses the sameGetEdmModelForCatalogmethod, as shown in the following code:// GET /catalog/v1, /catalog/v2, and so on. .AddRouteComponents(routePrefix: "catalog/v{version}", model: GetEdmModelForCatalog()) - In
ProductsController.cs, modify theGetmethods to add astringparameter namedversionthat defaults to"1"...