OData v4 Client Code Generator

Microsoft Free

An item template that simplifies the process of accessing OData v4 services by generating C# and VB.Net client-side proxy classes.

Microsoft
(0) Review
Visual Studio
2013, 2012, 2010
Download (3,812)
7/9/2014
2.0.0
View
E-mail Twitter del.icio.us Digg Facebook
Add to favorites
Description
Reviews
Q and A (6)
Sign in to write a review

Be the first to write a review.

Sign in to start a discussion


  • Authentication support
    2 Posts | Last post Tue 6:53 AM
    • As of version 2.0.0 there is not authentication support.  One must download the edmx as a file and then point the Text Template to the file.  This is an unnecessary step and was supported with OData 1-3 Update Service Reference built into VS. In the annoucement post on the OData Team blog (http://blogs.msdn.com/b/odatateam/archive/2014/07/09/odata-client-code-generator-2-0-0-release.aspx), the comments show several users are confused by this.  When will you be adding authentication support?  Are you currently working on this?  Thank you.
    • Hi AdamCaviness, thanks for your suggestions. We totally understand that it might not be that convenient for you to download the edmx to a local file, and the good news is that you can add the authentication support to T4 Template by yourself according to this tutorial http://blogs.msdn.com/b/odatateam/archive/2014/06/23/how-to-enable-authentication-for-metadata-documents-in-the-odata-client-code-generator.aspx
      Will this work for you?
  • Bug when using Where clause and no results returned
    1 Posts | Last post July 21, 2014
    • Let's assume you have an odata model called customer with 2 properties. ID and CustomerName. Let's also assume there is NO customer record in the database that has an ID of 2.
      
      Now from the client you have the following:
      (from x in dbContext.Customer where x.ID = 2 select x.ID, x.CustomerName)
      This line of code will fail.
      "The 'ObjectContent`1' type failed to serialize the response body for content type" AND
      ""'SingleResult`1' cannot be serialized using the ODataMediaTypeFormatter."
      
      but if you change to code to use the "AddQueryOption" then it works.
      (from x in dbContext.Customer.AddQueryOption("$filter", "ID eq 2") select x.ID, x.CustomerName)
      works just fine.
      
      Please NOTE there is NO customer record of ID = 2 in the database.
  • Bug when selecting single property
    1 Posts | Last post July 21, 2014
    • Let's assume you have an odata model called customer with 2 properties. ID and CustomerName.
      Now from the client you have the following:
      (from x in dbContext.Customer where x.ID == 3 select x.ID)
      This line of code will fail.
      "No HTTP resource was found that matches the request URI 'http://localhost:63344/odata/Customer(3)/ID"
      
      but if you change to code to select more property then it works.
      (from x in dbContext.Customer where x.ID == 3 select x.ID, x.CustomerName)
      works just fine.
      'http://localhost:63344/odata/Customer(3)?select=ID,CustomerName'
      
      Notice the URL has the select where the previous URL does not.
      
  • Customizable DataServiceContext class name
    5 Posts | Last post June 26, 2014
    • May you please add a Parameter to the config file for configuring the Context name? Such as <Parameter Name="DataServiceContextName" Value="Context" />  As it is now, the default name is "Container" and that word has too many connotations I'm afraid.  I would normally advocate users just change the tt for this sort of thing but this is such a common desire I'd recommend it be a Parameter.  Thanks.
    • The name of the context class is the same as the namespace defined in the metadata document. Such as for <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ODataDemo">, the generated context class name is "ODataDemo". So if you own the implementation of the target OData service, you may want to change the namespace of the service to avoid such common name. Will this resolve your problem?
    • @Yi Ding, thanks for your response but this is not at all what I am seeing. My metadata document returns <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="WebApiServer.Data.Entities"> but the client DataServiceContext class is generated as  public partial class Container : global::Microsoft.OData.Client.DataServiceContext.  I thought possibly "Data" or "Entities" may be reserved keywords so I changed the namespace of the target OData service like so <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="WebApiServer"> and the client generated DataServiceContext class name remains Container!  
      
      At line 2062 of the T4 template I see:
          /// <summary>
          /// There are no comments for <#= containerName #> in the schema.
          /// </summary>
          public partial class <#= fixedContainerName #> : global::Microsoft.OData.Client.DataServiceContext
          {
      <#+
          }
      
      I'm using VS2013 with Update 2.  On the server I'm using Web API 2.2 5.2.0-rtm with "OData team" libs of 6.4.0.
    • Sorry AdamCaviness that I made a mistake in this. The name of the class should be identical to the name of the EntityContainer (e.g. if there is <EntityContainer Name="InMemoryEntities"> in the metadata document then the generated class derived from DataServiceContext will be named "InMemoryEntities").
      
      In addition, the generated classes are contained in a namespace, whose name is configurable in the .tt file by modifying the "NamespacePrefix" in it. It's by default the same name as the name of the project in VS. So let's say you have this project named "DotNetClient" and a service whose entity container name is "Container", then the class generated that derives from DataSerivceContext will be "DotNetClient.Container". Thus, changing the namespace of the generated class also helps to resolve the possible name collision. Would this be OK?
    • @Yi Ding, thank you for the clarification.  It was not immediately discoverable to me how to change that EntityContainer name.  On my ODataConventionModelBuilder instance in the Web API server, I set the ContainerName property.  
      
      var builder = new ODataConventionModelBuilder();
      builder.ContainerName = "Context";
      
      Thanks again.
  • OData 4 has function binding but not the T4 template
    2 Posts | Last post June 10, 2014
    • The Web API 2.2 OData v4.0 supports functions defined on the model and the metadata show the supported functions but the T4 template does not generate any code based on this new OData v4.0 feature. Will functions be supported in the new proxy generated code?
    • Dear ImGonaRot, the functions will be supported by the OData Client Code Generator in our recent release in June.
  • OData v3.0 support
    2 Posts | Last post June 10, 2014
    • Is there a plan to support generating clients for endpoints of OData v3.0 format?
    • Dear nedarb760, currently in order to generate client side proxy for V3 services, you can use Add Service Reference: http://msdn.microsoft.com/en-us/library/bb628652.aspx