Reading Custom Annotation from $metadata URI for Open Data Service

Topics: General, OData Library, WCF Data Services
Aug 29, 2012 at 10:52 AM

Hello All,

I would like to quickly check if it is possible to read custom annotation at client side. If not are there any workarounds?

<Property xmlns:p8="" 

Name="CategoryID" Type="Edm.Int32" Nullable="false"p8:StoreGeneratedPattern="Identity"/> 

For example, in above example, "Identity" is value of custom annotation.

Thanks in advance.

Viral Thakkar

Aug 29, 2012 at 4:24 PM


Assuming you're using EdmLib to parse the $metadata, that is you get it as IEdmModel, you can use this extension method GetAnnotationValue to get the value of that parameter.


Vitek Karas

Aug 30, 2012 at 5:44 AM



Thanks a lot for your reply.

I tried what you are saying but unfortunately that is not working.

I hope I am doing it correctly. To make sure that, sharing few more information.

I am hitting one of the public services.$metadata

I am getting edmmodel in following way:

IEdmModel edmmodel = messageReader.ReadMetadataDocument();                

and then

edmmodel.GetAnnotationValue((IEdmElement)edmmodel.SchemaElements.First(), "", "StoreGeneratedPattern");

Above thing gives me null.

Please suggest.

Viral Thakkar


Sep 1, 2012 at 7:05 PM


The problem is that you're asking the right question on a wrong element. edmmodel.SchemaElements.First() on the northwind model will return the Category EntityType. That itself doesn't have any annotation StoreGeneratedPattern.

Try this instead:

var annotation = model.GetAnnotationValue(


Sep 3, 2012 at 12:28 PM

Yes. It is working now. Thanks a lot...