title: Azure Table Storage - Generic download for any type extending ITableEntity
body: <p>I have four custom data types, each of which extends <code>ITableEntity</code>, which is part of the <code>WindowsAzure.Storage</code> package. </p>
  
  <p>Right now, I have four different methods for downloading data from the Azure Table storage. Each follows this format:</p>
  
  <pre><code>public List&lt;MyCustomEntity&gt; DownloadMyCustomEntities(string tableId)
  {
      // Reference the CloudTable object
      CloudTable table = tableClient.GetTableReference(tableId);
  
      TableQuery&lt;MyCustomEntity&gt; query = new TableQuery&lt;MyCustomEntity&gt;();
      return new List&lt;MyCustomEntity&gt;(table.ExecuteQuery(query));
  }
  </code></pre>
  
  <p>Instead of having one of these methods for each of my custom entity types, I am trying to create one shared function. I'm hoping this is possible, as all of my custom types inherit from <code>ITableEntity</code>.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>public List&lt;TableEntity&gt; DownloadAnyEntity(string tableId)
  {
      // Reference the CloudTable object
      CloudTable table = tableClient.GetTableReference(tableId);
  
      TableQuery&lt;TableEntity&gt; query = new TableQuery&lt;TableEntity&gt;();
      return new List&lt;TableEntity&gt;(table.ExecuteQuery(query));
  }
  </code></pre>
  
  <p>I've tried this with <code>TableEntity</code> and <code>ITableEntity</code>, but I keep getting errors. For <code>TableEntity</code>, my error is that no cast exists to the type I actually need (when I call the <code>DownloadAnyEntity</code> method), whereas I feel it should be implicit since it is an extension of <code>ITableEntity</code>.</p>
  
  <p>For <code>ITableEntity</code>, I get an error that <code>ExecuteQuery</code> input must be a non-abstract type with a public parameterless constructor. All of my four custom types have public parameterless constructors.</p>
  
  <p>I feel like the issue I'm seeing is more to do with not fully understanding inheritance, more so that it being Azure Table Storage specific. Any pointers much appreciated. </p>
  
  <p>I've largely been following <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet" rel="noreferrer">this documentation</a>, but there is no example for a non type-specific entity download method.</p>