title: Return a single entity from OData - .Net
body: <p>I need to do a request on an OData service that would retrieve a single entity and that should look like this:
  <a href="http://server.com/odata_srv/EntitySet(par1=value1,%E2%80%A6,parn=valuen)" rel="nofollow noreferrer">/EntitySet(par1=value1,…,parn=valuen)</a></p>
  
  <p>However, my LINQ generated query for fetching the entry looks like this:
  <a href="http://server.com/odata_srv/EntitySet()?$filter=(par1%20eq%20value1)%20and%20(par2%20eq%20value2)%20and%20...%20(parn%20eq%20valuen)" rel="nofollow noreferrer">/EntitySet()?$filter=(par1 eq value1) and (par2 eq value2) and ... (parn eq valuen)</a></p>
  
  <p>This is, of course, valid. But the server does not allow it. It only agrees with the first option, the one with the criteria in parentheses.</p>
  
  <p>Is there something I can do? It would be a shame to manually create the query URL...</p>
  
  <p>Here's the code:</p>
  
  <pre><code>        var context = new CHART_SRV_Entities(oDataUri);
  
          var query = context.ApplicationData.Where(ad =&gt;
              ad.institution == "1" &amp;&amp;
              ad.patientId == "2000118" &amp;&amp;
              ad.caseId == "2488");
  
          DataServiceCollection&lt;ApplicationData&gt; data = new DataServiceCollection&lt;ApplicationData&gt;(context);
  
          data.LoadCompleted += (s, args) =&gt;
              {
                  if (args.Error == null)
                  {
                      if (data.Continuation != null)
                      {
                          data.LoadNextPartialSetAsync();
                      }
                      else
                      {
                          var result = data;
                      }
                  }
                  else
                  {
                      MessageBox.Show(args.Error.Message);
                  }
              };
  
          data.LoadAsync(query);
  </code></pre>
  
  <p><strong>Update:</strong> A "parentheses request" was achieved with CreateQuery <a href="https://stackoverflow.com/questions/23493451/how-to-create-query-expression-for-odata-for-get-by-id">here</a>. However, that's a synchronous call. Any ideas on how to make it async?</p>
  
  <p><strong>Update2:</strong> Seems that what I'm trying to achieve is an OData composite key lookup. There's this <a href="https://github.com/object/Simple.OData.Client/wiki/Retrieving-a-single-row-by-key" rel="nofollow noreferrer">OData library</a> that can do it, but I find it hard to believe that this can't be done with the Microsoft toolset.</p>