Search code examples
c#odataedmx

odata class generation from edmx model


I am trying to work with data from an existing ODATA endpoint in code for another ODATA API.

I have no desire to recreate all the models manually and so I was hoping to use the existing edmx models to create the classes in C# that I need.

I looked into the "odata client code generator" offered by Microsoft and this seems like the perfect solution, but I can only get it to work if I connect directly to a service endpoint... it doesn't work if I download the edmx file and try to use that (even though the tutorial says you can use a URL OR a file).

Has anyone actually been able to successfully connect this odata client code generator to an edmx file?

If I can't get this working, does anyone have other suggestions for how to generate the classes I need from these edmx models?

I am specifically trying to work with the metadata from Microsoft Project Online. It gives an endpoint like this: https://[domain]/sites/pwa/_api/ProjectData/$metadata

I can't connect directly to this unfortunately because it requires authentication and the odata client code generator doesn't support authentication...


Solution

  • It appears VS 2017 is not supported by the odata client code generation tool. I am trying out VS 2015 now.

    Edit: I have confirmed that the client code generation tool works with visual studio community 2015. I couldn't get it to work because I was running it under visual studio professional 2017... Microsoft employees have reported on a couple of forums that this tool isn't support under VS 2017.

    Also, I found out this this service still won't work with the OData client code generator anyway since it is OData V3 and the tool only works with OData V4. You must use DataSvcUtil.exe to generate code from earlier versions of OData. I downloaded the .edmx file and run the following command to generate the classes:

    "%windir%\Microsoft.NET\Framework\v3.5\DataSvcUtil.exe" /dataservicecollection /version:2.0 /language:CSharp /out:TestOutput.cs /in:C:\Users\[username]\DevelLocal\test1.edmx