Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revisions capability doc #190

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Odata-docs/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
items:
- name: Capabilities vocabulary extensions
href: /odata/webapi/model-builder-capabilities-vocabulary
- name: Revisions vocabulary annotations
href: /odata/webapi/model-builder-revisions-capabilities
- name: Non-convention model builder
href: /odata/webapi/model-builder-nonconvention
- name: Routing
Expand Down
175 changes: 175 additions & 0 deletions Odata-docs/webapi/model-builder-revisions-capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
title: "Adding Revisions Annotations with the OData Model Builder"
description: "core capabilities vocabulary"
author: ElizabethOkerio
ms.author: elokerio
ms.date: 7/22/2021
---

# Adding Revisions Annotations with the OData Model Builder

**Applies To**:[!INCLUDE[appliesto-webapi](../includes/appliesto-webapi-v7.md)][!INCLUDE[appliesto-webapi](../includes/appliesto-webapi-v6.md)]

The model builder now allows you to add [revisions annotations](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.xml#L77) to your model elements. Please [follow the link](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md) for more information on [core capabilities vocabulary](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md).

It is available in the [Nuget gallery](https://www.nuget.org/packages/Microsoft.OData.ModelBuilder)

You can install or update the NuGet package for OData Migration Extensions v1.0.0 using the [Package Manager Console](https://docs.nuget.org/docs/start-here/using-the-package-manager-console):

```PowerShell
PM> Install-Package Microsoft.OData.ModelBuilder
```
## Examples

Unless otherwise specified, examples will be based on the model below.

```csharp
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
}

public class Address
{
public string City {get;set;}
}

public enum Color
{
Red,
Green,
Blue
}
```
Revisions can be added to all model elements. So far, the OData Model Builder supports revisions to the following model elements:

1. EntitySets
1. Actions and Action Imports
1. Functions and Function Imports
1. Entity Types
1. Complex Types
1. Enum Types
1. Enum Members
Comment on lines +47 to +53
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. EntitySets
1. Actions and Action Imports
1. Functions and Function Imports
1. Entity Types
1. Complex Types
1. Enum Types
1. Enum Members
1. EntitySets
2. Actions and Action Imports
3. Functions and Function Imports
4. Entity Types
5. Complex Types
6. Enum Types
7. Enum Members

1. Properties
ElizabethOkerio marked this conversation as resolved.
Show resolved Hide resolved

There are three kinds of revisions that can be added to any of the model elements above:

```csharp
enum RevisionKind
{
//when a model element is added
Added,

//when a model element is modified
Modified,

//when a model elemeny is deprecated
Deprecated
}
```


To add revisions to an entity set for example, use the code below:

```csharp
var builder = new ODataConventionModelBuilder();
var customerConfiguration = builder.EntitySet<Customer>("Customers").HasRevisions(a => a.HasVersion("v1.2").HasKind(RevisionKind.Added).HasDescription("Added a new entity set"));
```

Use this structure to add revisions to all the other supported model elements above.

$metadata

```xml
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
<EntityType Name="Customer">
<Key>
<PropertyRef Name="CustomerId" />
</Key>
<Property Name="CustomerId" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<EntityContainer Name="Container">
<EntitySet Name="Customers" EntityType="Default.Customer" />
</EntityContainer>
<Annotations Target="Default.Container/Customers">
<Annotation Term="Org.OData.Core.V1.Revisions">
<Collection>
<Record>
<PropertyValue Property="Version" String="v1.2" />
<PropertyValue Property="Kind">
<EnumMember>Org.OData.Core.V1.RevisionKind/Added</EnumMember>
</PropertyValue>
<PropertyValue Property="Description" String="desc" />
</Record>
</Collection>
</Annotation>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
```
To add a revision, you must provide the following properties:
1. RevisionKind - the kind of revision you are making. Added, Modified or Deprecated.
1. Description - a description describing the revision you are making.
1. Version - the version of the model the revision was made.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all of these be numbered 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how to number items in .md file..I don't think it will appear like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's how it will appear


You can add also dynamic properties to provide more information for the model elements' revisions. Below is an example on how to add extra properties to a revision.

```csharp

var builder = new ODataConventionModelBuilder();
var config = builder.EntitySet<Customer>("Customers").HasRevisions(a => a.HasVersion("v1.2").HasKind(RevisionKind.Deprecated).HasDescription("The M").HasDynamicProperty("Date", new DateTime(2021,11,11)).HasDynamicProperty("RemovalDate", new DateTime(2022,12,12)));

```
$metadata

```xml
<?xml version="1.0" encoding="UTF-8"?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="CoreCapabilities">
<EntityType Name="Customer">
<Key>
<PropertyRef Name="CustomerId" />
</Key>
<Property Name="CustomerId" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<EntityContainer Name="Container">
<EntitySet Name="Customers" EntityType="CoreCapabilities.Customer" />
</EntityContainer>
<Annotations Target="Default.Container/Customers">
<Annotation Term="Org.OData.Core.V1.Revisions">
<Collection>
<Record>
<PropertyValue Property="Version" String="v1.2" />
<PropertyValue Property="Kind">
<EnumMember>Org.OData.Core.V1.RevisionKind/Deprecated</EnumMember>
</PropertyValue>
<PropertyValue Property="Description" String="The M" />
<PropertyValue Property="Date" DateTimeOffset="2021-11-11T00:00:00+03:00" />
<PropertyValue Property="RemovalDate" DateTimeOffset="2022-12-12T00:00:00+03:00" />
</Record>
</Collection>
</Annotation>
</Annotations>
</Schema>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Default">
<EntityContainer Name="Container">
<EntitySet Name="Customers" EntityType="CoreCapabilities.Customer" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

```





Comment on lines +171 to +175
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change