Question

I wanted to ask what is "<d:ID>" attribute exactly is used for in OData ?

I have attached sample service where "ID" (it is defined as entity key") is present.(see code block below)

We have nested entries in response xml like here Product & Categories. Product contains Categories (see code block below)

Example: Let say I have 1st Product "TV" which comes under 2 different Categories "Electrical" "ID=1" & "electronics" "ID=2" ...2nd Product "Milk" which comes under Categories "Beverages" "ID=1" & "drink" "ID=5" and I am getting all this data in same response.

Here if you see in example "Electrical" & "Beverages" have same ID( which is 1) but they are present inside different products. Is this case is possible ?

Code Block:

 <?xml version="1.0" encoding="utf-8" ?> 
    - <feed xml:base="http://services.odata.org/V3/OData/OData.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
      <id>http://services.odata.org/V3/OData/OData.svc/Products</id> 
      <title type="text">Products</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
      <link rel="self" title="Products" href="Products" /> 
    - <entry>
      <id>http://services.odata.org/V3/OData/OData.svc/Products(0)</id> 
      <category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
      <link rel="edit" title="Product" href="Products(0)" /> 
    - <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories" type="application/atom+xml;type=feed" title="Categories" href="Products(0)/Categories">
    - <m:inline>
    - <feed>
      <id>http://services.odata.org/V3/OData/OData.svc/Products(0)/Categories</id> 
      <title type="text">Categories</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
      <link rel="self" title="Categories" href="Products(0)/Categories" /> 
    - <entry>
      <id>http://services.odata.org/V3/OData/OData.svc/Categories(0)</id> 
      <category term="ODataDemo.Category" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
      <link rel="edit" title="Category" href="Categories(0)" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" type="application/atom+xml;type=feed" title="Products" href="Categories(0)/Products" /> 
      <title type="text">Food</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
    - <author>
      <name /> 
      </author>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Products" type="application/xml" title="Products" href="Categories(0)/$links/Products" /> 
    - <content type="application/xml">
    - <m:properties>
      <d:ID m:type="Edm.Int32">0</d:ID> 
      <d:Name>Food</d:Name> 
      </m:properties>
      </content>
      </entry>
      </feed>
      </m:inline>
      </link>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(0)/Supplier" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail" type="application/atom+xml;type=entry" title="ProductDetail" href="Products(0)/ProductDetail" /> 
      <title type="text">Bread</title> 
      <summary type="text">Whole grain bread</summary> 
      <updated>2014-01-07T15:47:23Z</updated> 
    - <author>
      <name /> 
      </author>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml" title="Categories" href="Products(0)/$links/Categories" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml" title="Supplier" href="Products(0)/$links/Supplier" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml" title="ProductDetail" href="Products(0)/$links/ProductDetail" /> 
    - <content type="application/xml">
    - <m:properties>
      <d:ID m:type="Edm.Int32">0</d:ID> 
      <d:ReleaseDate m:type="Edm.DateTimeOffset">1992-01-01T00:00:00Z</d:ReleaseDate> 
      <d:DiscontinuedDate m:null="true" /> 
      <d:Rating m:type="Edm.Int16">4</d:Rating> 
      <d:Price m:type="Edm.Double">2.5</d:Price> 
      </m:properties>
      </content>
      </entry>
    - <entry>
      <id>http://services.odata.org/V3/OData/OData.svc/Products(1)</id> 
      <category term="ODataDemo.Product" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
      <link rel="edit" title="Product" href="Products(1)" /> 
    - <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Categories" type="application/atom+xml;type=feed" title="Categories" href="Products(1)/Categories">
    - <m:inline>
    - <feed>
      <id>http://services.odata.org/V3/OData/OData.svc/Products(1)/Categories</id> 
      <title type="text">Categories</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
      <link rel="self" title="Categories" href="Products(1)/Categories" /> 
    - <entry>
      <id>http://services.odata.org/V3/OData/OData.svc/Categories(0)</id> 
      <category term="ODataDemo.Category" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
      <link rel="edit" title="Category" href="Categories(0)" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" type="application/atom+xml;type=feed" title="Products" href="Categories(0)/Products" /> 
      <title type="text">Food</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
    - <author>
      <name /> 
      </author>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Products" type="application/xml" title="Products" href="Categories(0)/$links/Products" /> 
    - <content type="application/xml">
    - <m:properties>
      <d:ID m:type="Edm.Int32">0</d:ID> 
      <d:Name>Food</d:Name> 
      </m:properties>
      </content>
      </entry>
    - <entry>
      <id>http://services.odata.org/V3/OData/OData.svc/Categories(1)</id> 
      <category term="ODataDemo.Category" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> 
      <link rel="edit" title="Category" href="Categories(1)" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" type="application/atom+xml;type=feed" title="Products" href="Categories(1)/Products" /> 
      <title type="text">Beverages</title> 
      <updated>2014-01-07T15:47:23Z</updated> 
    - <author>
      <name /> 
      </author>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Products" type="application/xml" title="Products" href="Categories(1)/$links/Products" /> 
    - <content type="application/xml">
    - <m:properties>
      <d:ID m:type="Edm.Int32">1</d:ID> 
      <d:Name>Beverages</d:Name> 
      </m:properties>
      </content>
      </entry>
      </feed>
      </m:inline>
      </link>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Supplier" type="application/atom+xml;type=entry" title="Supplier" href="Products(1)/Supplier" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ProductDetail" type="application/atom+xml;type=entry" title="ProductDetail" href="Products(1)/ProductDetail" /> 
      <title type="text">Milk</title> 
      <summary type="text">Low fat milk</summary> 
      <updated>2014-01-07T15:47:23Z</updated> 
    - <author>
      <name /> 
      </author>
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Categories" type="application/xml" title="Categories" href="Products(1)/$links/Categories" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Supplier" type="application/xml" title="Supplier" href="Products(1)/$links/Supplier" /> 
      <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/ProductDetail" type="application/xml" title="ProductDetail" href="Products(1)/$links/ProductDetail" /> 
    - <content type="application/xml">
    - <m:properties>
      <d:ID m:type="Edm.Int32">1</d:ID> 
      <d:ReleaseDate m:type="Edm.DateTimeOffset">1995-10-01T00:00:00Z</d:ReleaseDate> 
      <d:DiscontinuedDate m:null="true" /> 
      <d:Rating m:type="Edm.Int16">3</d:Rating> 
      <d:Price m:type="Edm.Double">3.5</d:Price> 
      </m:properties>
      </content>
      </entry>
    </feed>
Was it helpful?

Solution

ID is just another attribute belonging to the entity Product as defined by the service's schema. Like Product's other attributes defined in the schema (Name, Description, ReleaseDate, etc.) there isn't a guarantee of uniqueness, unless the attribute is also defined as the entity's Key. In this case ID is in fact Product's Key, so we know ID will be unique for all Product entities.

In the same schema the Category entity also has a property ID, which serves as that entity's Key. This means that each Product will have an ID value unique among all Products, and each Category will have an ID value unique among all Categories.

To illustrate this a bit better, try this query out at the OData API explorer to show the Categories belonging to each Product:
http://services.odata.org/V3/OData/OData.svc/Products?$expand=Categories

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top