title: How to batch retrieve entities?
body: <p><strong>In Azure table storage, how can I query for a set of entities that match specific row keys in a partition???</strong></p>
  
  <p>I'm using Azure table storage and need to retrieve a set of entities that match a set of row keys within the partition.</p>
  
  <p>Basically if this were SQL it may look something like this:</p>
  
  <pre><code>SELECT TOP 1 SomeKey
  FROM TableName WHERE SomeKey IN (1, 2, 3, 4, 5);
  </code></pre>
  
  <p>I figured to save on costs and reduce doing a bunch of table retrieve operations that I could just do it using a table batch operation. For some reason I'm getting an exception that says:</p>
  
  <blockquote>
    <p>"A batch transaction with a retrieve operation cannot contain any other operations"</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>public async Task&lt;IList&lt;GalleryPhoto&gt;&gt; GetDomainEntitiesAsync(int someId, IList&lt;Guid&gt; entityIds)
  {
      try
      {
          var client = _storageAccount.CreateCloudTableClient();
          var table = client.GetTableReference("SomeTable");
          var batchOperation = new TableBatchOperation();
          var counter = 0;
          var myDomainEntities = new List&lt;MyDomainEntity&gt;();
  
          foreach (var id in entityIds)
          {
              if (counter &lt; 100)
              {
                  batchOperation.Add(TableOperation.Retrieve&lt;MyDomainEntityTableEntity&gt;(someId.ToString(CultureInfo.InvariantCulture), id.ToString()));
                  ++counter;
              }
              else
              {
                  var batchResults = await table.ExecuteBatchAsync(batchOperation);
                  var batchResultEntities = batchResults.Select(o =&gt; ((MyDomainEntityTableEntity)o.Result).ToMyDomainEntity()).ToList();
                  myDomainEntities .AddRange(batchResultEntities );
                  batchOperation.Clear();
                  counter = 0;
              }
          }
  
          return myDomainEntities;
      }
      catch (Exception ex)
      {
          _logger.Error(ex);
          throw;
      }
  }
  </code></pre>
  
  <p>How can I achieve what I'm after without manually looping through the set of row keys and doing an individual Retrieve table operation for each one? I don't want to incur the cost associated with doing this since I could have hundreds of row keys that I want to filter on.</p>