title: How do I convert CRM Online $metadata XML to C# classes?
body: <p>I used to generate early bound classes for Dynamics CRM using <a href="https://msdn.microsoft.com/en-us/library/gg327844.aspx" rel="nofollow noreferrer">CrmSvcUtil and the 2011 endpoint</a>.<br>
  This still works but is due to be deprecated so <strong>I'm trying to understand the new OData endpoint and use this to generate the classes</strong>.</p>
  
  <p>You can view the entity model XML for CRM by browsing to the appropriate URL:</p>
  
  <blockquote>
    <p><a href="https://myorg.crm4.dynamics.com/api/data/v8.1/" rel="nofollow noreferrer">https://myorg.crm4.dynamics.com/api/data/v8.1/</a>$metadata</p>
  </blockquote>
  
  <p>Or alternatively you can just download the XML from the developer section in CRM:</p>
  
  <p><a href="https://i.stack.imgur.com/SyX3Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SyX3Z.png" alt="download odata metadata"></a></p>
  
  <p>In either case you end up with the XML defining the entity model:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"&gt;
    &lt;edmx:Reference Uri="http://vocabularies.odata.org/OData.Community.Keys.V1.xml"&gt;
      &lt;edmx:Include Namespace="OData.Community.Keys.V1" Alias="Keys" /&gt;
      &lt;edmx:IncludeAnnotations TermNamespace="OData.Community.Keys.V1" /&gt;
    &lt;/edmx:Reference&gt;
    &lt;edmx:Reference Uri="http://vocabularies.odata.org/OData.Community.Display.V1.xml"&gt;
      &lt;edmx:Include Namespace="OData.Community.Display.V1" Alias="Display" /&gt;
      &lt;edmx:IncludeAnnotations TermNamespace="OData.Community.Display.V1" /&gt;
    &lt;/edmx:Reference&gt;
    .... blah blah ....
  </code></pre>
  
  <p><strong>How do I convert this to a set of strongly typed C# classes?</strong></p>
  
  <p>I found <a href="https://yanivrdt.wordpress.com/2015/09/27/crm-web-api-preview-generate-strongly-typed-objects-from-metadata-document/" rel="nofollow noreferrer">this guide which recommends using the OData v4 Client Code Generator tool</a> but this seems like overkill and I'd rather avoid using tools that may cease to work in the future.</p>
  
  <p>I also saw the <a href="https://msdn.microsoft.com/en-us/library/dd756369(v=vs.110).aspx" rel="nofollow noreferrer">MSDN article for DataSvcUtil.exe</a> which can convert EDMX files but I have an XML. I tried changing the file extension but it won't convert, it throws an error:</p>
  
  <blockquote>
    <p>error 7001: The 'Scale' attribute is invalid - The value 'Variable' is invalid according to its datatype '<a href="http://schemas.microsoft.com/ado/2007/05/edm:TScaleFacet" rel="nofollow noreferrer">http://schemas.microsoft.com/ado/2007/05/edm:TScaleFacet</a>' - The string 'Variable' is not a valid Integer value.<br>
          The string 'Variable' is not a valid Integer value.</p>
  </blockquote>
  
  <p>I'm now stuck and not sure which is the recommended way to do this.</p>