Search code examples
c#odatadynamics-crm

How to connect to OData service with generated OData client?


I generated the client code from a for OData V4 service (Dynamics 365 metadata) using the OData V4 Client Code Generator project template (https://marketplace.visualstudio.com/items?itemName=bingl.ODatav4ClientCodeGenerator).

The code was generated fine and it compiles. Now the problem is that I simply cannot find a way to make a connection (or context) that can be used when querying data (OData linq queries for example).

All the examples I've read basically just "start right away" with having a Context or a Resource available, but none of them actually specify why or how it's there.

For example https://blogs.msdn.microsoft.com/odatateam/2014/03/11/tutorial-sample-how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class/ shows how to generate the classes and then creates an instance of NorthwindEntities (or XxxxEntities) which, again, I don't have generated (I don't have anything named "Entities" in the generated code).

https://stoneridgesoftware.com/working-with-the-odata-endpoint-in-dynamics-365-for-operations/ just simply creates a new instance of Resources class, which I don't have (what is it?). I have nothing named Resources in the generated code.

Obviously it can't be this difficult so maybe I'm missing something.

EDIT: the generated class contains only classes Crmbaseentity, CrmbaseentitySingle, ExtensionMethods and then the entity classes themselves. There simply are no other classes.

Any ideas how to do this differently or any blog posts that I've missed?


Solution

  • The problem was that I used the code generation template from https://github.com/Microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples/ODataUtility. When I added the OData service to the project as a "service refernce" and used the wizard, then the code was generated normally.

    I still don't know the actual reason why the T4 template didn't work.