title: Batch Insert in Azure storage table
body: <p>I am new to using azure storage table. I was trying to insert my entities in batch but I found that you cannot do batch operation having different partition key.</p>
  
  <p>Is there some way I can do that there are about 10,000 - 20,000 of file details which I want to insert in a table.</p>
  
  <p>Here is what I have tried so far : </p>
  
  <pre><code>public class Manifest:TableEntity
  {
      private string name;
      private string extension;
      private string filePath;
      private string relativePath;
      private string mD5HashCode;
      private string lastModifiedDate;
  
      public void AssignRowKey()
      {
          this.RowKey = relativePath.ToString();
      }
      public void AssignPartitionKey()
      {
          this.PartitionKey = mD5HashCode;
      }
      public string Name { get { return name; } set { name = value; } }
      public string Extension { get { return extension; } set { extension = value; } }
      public string FilePath { get { return filePath; } set { filePath = value; } }
      public string RelativePath { get { return relativePath; } set { relativePath = value; } }
      public string MD5HashCode { get { return mD5HashCode; } set { mD5HashCode = value; } }
      public string LastModifiedDate { get { return lastModifiedDate; } set { lastModifiedDate = value; } }
  
  }
  </code></pre>
  
  <p>My method this is in different class:</p>
  
  <pre><code>static async Task BatchInsert(CloudTable table, IEnumerable&lt;FileDetails&gt; files)
      {
          int rowOffset = 0;
  
          var tasks = new List&lt;Task&gt;();
  
          while (rowOffset &lt; files.Count())
          {
              // next batch
              var rows = files.Skip(rowOffset).Take(100).ToList();
  
              rowOffset += rows.Count;                
  
              var task = Task.Factory.StartNew(() =&gt;
              {                  
  
                  var batch = new TableBatchOperation();
  
                  foreach (var row in rows)
                  {
                      Manifest manifestEntity = new Manifest
                      {
                          Name = row.Name,
                          Extension = row.Extension,
                          FilePath = row.FilePath,
                          RelativePath = row.RelativePath.Replace('\\', '+'),
                          MD5HashCode = row.Md5HashCode,
                          LastModifiedDate = row.LastModifiedDate.ToString()
                      };
                      manifestEntity.AssignPartitionKey();                        
                      manifestEntity.AssignRowKey();
                      batch.InsertOrReplace(manifestEntity);
                  }
  
                  // submit
                  table.ExecuteBatch(batch);
  
              });
  
              tasks.Add(task);
          }
  
           await Task.WhenAll(tasks);
  }
  </code></pre>