Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate OData metadata

Tags:

c#

metadata

odata

How to iterate OData metadata? I need to iterate all entities, their properties with types, keys and navigation properties (all available information to be precise), but I got stuck since SchemaElements returns objects of internal types (Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsEntityContainer) and I cannot cast them to get all this information.

var metadata = await _client.GetMetadataAsync();

foreach (var element in metadata.SchemaElements)

where client is declared this way:

Simple.OData.Client.ODataClient _client;

like image 401
Access Denied Avatar asked Oct 30 '22 13:10

Access Denied


2 Answers

After installing https://marketplace.visualstudio.com/items?itemName=bingl.ODatav4ClientCodeGenerator add new item, T4 code of that file, iterate almost all aspects of $metadata to generate c# odata proxy for you, you can use those codes to find your way

like image 163
Yaser Moradi Avatar answered Nov 15 '22 03:11

Yaser Moradi


If you can use https://www.nuget.org/packages/Microsoft.OData.Client/6.5.0 (note: this library is for OData v4 only), for v3 use https://www.nuget.org/packages/Microsoft.Data.OData/.

ODataServiceDocument has property EntitySets.

like image 20
Andrey Belykh Avatar answered Nov 15 '22 02:11

Andrey Belykh