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
(1) Review
Visual Studio
2013, 2012, 2010
Download (13,067)
2/16/2015
2.2.0
View
E-mail Twitter del.icio.us Digg Facebook
Add to favorites
Description
Reviews (1)
Q and A (16)
Sign in to write a review
Sort by:

by ImGonaRot | November 26 2014

Great start but falls short in a few areas such as authentication and function / action calls.

Sign in to start a discussion


  • Filtering a composable function result by the entity id property
    2 Posts | Last post February 16, 2015
    • I'm using a Web API OData service and have a client that uses the generator. Suppose we have an unbound and composable function which has the following metadata:
      
            <Function Name=""FunctionReturnsIQueryable"" IsComposable=""true"">
              <ReturnType Type=""Collection(WebTestsServer.Domain.ActionMethodsRoutingTests.PrimitiveEntity)"" />
            </Function>
      
      Here PrimitiveEntity is an entity. When I try to run the follwing query:
      
      (DataServiceQuery<PrimitiveEntity>)Client.FunctionReturnsIQueryable().Where(x => x.Id == 1).Execute();
      
      I can see in Fiddler the GET request for this url: http://localhost:59663/FunctionReturnsIQueryable()(1) 
      
      But it seems that the url should use the $filter query option instead, something like:
      http://localhost:59678/FunctionReturnsIQueryable()?$filter=Id eq 1 
      When I try to filter the query by any other entity property, not the identificator, I get the url like the last one and everything works fine.
      
      
    • @Ruslan Marchenko
      
      This is by design, when OData Client found that you are using the key property with 'eq' operator, it will translate it into a (key).But for other properties, it will translate it to $filter .
  • Expand is not working correctly
    1 Posts | Last post February 16, 2015
    • The expand is only showing the first object in the DataServiceCollection.
      For example: odata/Orders?$expand=OrderLines in a browser shows more than 1 order line.
      Also when using fiddler and the OData v4 Client Code Generator I can see that multiple order lines are being returned but once the OData v4 Client deserializes the json then it only adds the 1st item to the OrderLines property of Order.
      
  • Bug when calling IQueryable service with "KEY" that returns more than one objec
    4 Posts | Last post February 10, 2015
    • I have an IQueryable method on the OData server that when you pass it a "KEY" it will return multiple records.
      Think of it like OrderDetail service where you pass the OrderID to get all details.
      Like this.
      
      [EnableQuery()]
      public IQueryable<OrderDetail> GetOrderDetail([FromODataUri()]
      long key, ODataQueryOptions<OrderDetail> queryOptions)
          {
              var results = (from OD in db.OrderDetail where OD.OrderID == key);
              return results;
          }
      
      Now lets assume there are 2 order details that get returned.
      On the client if I use the OData client code like this:
      
          var results = (from OD in db.OrderDetail where OD.OrderID == 3 select OD).ToList();
      
      I do get 2 order details as expected BUT the second order detail is a exact copy of the first order detail.
      If I open Fiddler and look at the response I can see that there are 2 distinct order details returned but the OData client maps the first return to the second record.
      
      It gets even more interesting if you try to use the OData.Client.DataServicesCollection in that you only get 1 record back yet two are in the response.
      For example this will only return 1 record.
      
          var results = new New Microsoft.OData.Client.DataServiceCollection<OrderDetail>(from OD in db.OrderDetail where OD.OrderID == 3 select OD)
      
      
    • To provide access to a navigation property of the parent object you should declare the method in your OrdersController like this:
      [EnableQuery]
      public IQueryable<OrderDetail> GetOrderDetails([FromODataUri] int key)
      {
          return db.Orders.Where(order => order.Id == key).SelectMany(order => order.OrderDetails)
      }
      
      Hope that helps.
    • @David Totzke
      I'm sorry but that is the same thing I already have listed. 
      All you did was change the "long key" to "int key" and removed the "queryOptions".
      If you remove the queryOptions then you can add special logic like custom paging.
      The code I listed works fine when used outside of the Client Code Generator.
    • CORRECTION:  
      "If you remove the queryOptions then you can't add special logic like custom paging.
      The code I listed works fine when used outside of the Client Code Generator."
  • Project fails to build if Client Code Generator not installed.
    1 Posts | Last post January 30, 2015
    • I am working on a project that is kept in TFS.  I added the template to a project after installing the client code generator and everything works fine.  I check the source into TFS and then when a colleague gets latest and tries to compile the build will fail.  The bin folder is completely empty.  Not even the referenced assemblies are there. Even though the code has been generated previously and they have not tried to run custom tool.
      
      If my colleague then installs the extension the project will now build fine.
      
      The other way in which this problem manifests is that my builds in TFS are broken because of this.  I shouldn't have to install an extension on the build server to get pre-generated code to build.
      
      Does the code generation template come with its own assemblies that are not added as references to the project? (i.e. in the GAC perhaps) It seems very odd that the presence of the template in the project should have this effect. 
      
      What, if any, work-around is available for this issue?  Thanks.
  • How to get a list and total count with one call?
    2 Posts | Last post January 29, 2015
    • I notice there is a "IncludeTotalCount" extension method. It will include "$count" when calling the OData service. But how can I de-serialize the result into a structure with Total Count and a page of objects?
      
      For example:
      
      odataClient.Categories.Take(10).IncludeTotalCount().ToList() will return a list of 10 Categories but the Total Count is lost.
      
      
      Thanks!
      
      Richard
    • Figure out the answer: use QueryOperationResponse Execute method.
  • Error when odata return is empty or null
    2 Posts | Last post November 26, 2014
    • A simple LINQ with the OData client like 
          (from O in db.Orders where O.ID == -1 select O).ToList()
      where -1 does not exist will cause the following error
      "cannot be serialized using the ODataMediaTypeFormatter"
      
      The only way around this is to first call
          (from O in db.Orders where O.ID == -1 select O).Count()
      and then check the count and if the count is greater than zero call
          (from O in db.Orders where O.ID == -1 select O).ToList()
      
      But that is "2" trips to the service.
      
      Is there a better way without getting an exception?
      I tried to use LINQ DefaultIfEmpty but that is not supported with the OData client.
      
    • This does not seem to be a OData client issue but more of an OData controller issue.
      If I call the controller with an ID of -1 I get the same error.
  • Support for OAuth 2 and Bearer Token authorization
    1 Posts | Last post October 29, 2014
    • I use in my project OAuth 2 and Bearer Token to authorize access to resources. Is it exit any support for this and if is, can you show mi how to config or same tutorial where I find info? Thanks for helping and sorry for my English.
  • OData website down
    1 Posts | Last post October 21, 2014
    • I was going to pitch us using OData to other developers on my team, but the OData website (www.odata.org) is down.  Is Microsoft discontinuing support for OData?
      
  • Async Query - help
    2 Posts | Last post August 12, 2014
    • Using Nuget package Console manager to install latest version in visual studio. 
      
      I cannot find Microsoft.OData.Client.QueryResult.
      
      App1.Container cont = new Container(new Uri("http://localhost:11373/"));
      
      cont.BeginExecute(new Uri("http://localhost:11373/"), OnQueryCompleted, "", "GET", null);
      
      public void OnQueryCompleted(IAsyncResult result)
      {
      
      //result is of type Microsoft.OData.Client.QueryResult
      }
      
      
      Any help?
      
      
    •   DataServiceQuery query = (DataServiceQuery)from c in container.TestEntity select c;
              
       var task = Task<IEnumerable>.Factory.FromAsync(query.BeginExecute, query.EndExecute, query);
                  
                  await task;
      
                  var results = (Microsoft.OData.Client.QueryOperationResponse<TestEntity> )task.Result;
      
      
      This works correctly however.
      
  • Authentication support
    5 Posts | Last post August 05, 2014
    • 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?
    • @Junlin Zheng, Yes and thank you.
    • The link is only good for "Basic / Windows" authentication using "NetworkCredentials" and OData client < v2.0
      
      You can use a modified version to get "Forms" authentication to work.
      
      Also the original link is for the OData client v1 so you will have to make several adjustments to make it work correctly.
    • here is a help link for using "Forms" authentication with HttpWebRequest.
      http://www.ksingla.net/2006/08/sample_forms_authentication_test_in_csharp/
1 - 10 of 16 Items