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.OData
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 in the following code:
// GET /catalog/v1, /catalog/v2, and so on.
.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 the behavior of the methods if...