title: EF get list of records in runtime from Type
body: <p>Purpose:
  I need to loop all records like:</p>
  
  <pre><code>var records = db.Set&lt;UserAccount&gt;().ToList();
  </code></pre>
  
  <p>Then loop</p>
  
  <pre><code>foreach (var record in records)
  {
      // do something with the record 
  }
  </code></pre>
  
  <p>But it has to not type specific in runtime, as I am to loop through types and therefor do not know example "UserAccount".
  Only the Type/TypeOf?</p>
  
  <p>In the bottom of this description I have a method <strong>loopAllEntities</strong> that I cannot find a way to work</p>
  
  <p>I have created an DbContext with some entities.</p>
  
  <pre><code>public class MyEntities : DbContext
  {
      public DbSet&lt;UserAccount&gt; UserAccounts { get; set;}
      public DbSet&lt;UserRole&gt; UserRoles { get; set; }
      public DbSet&lt;UserAccountRole&gt; UserAccountRoles { get; set; }
  }
  </code></pre>
  
  <p>Defined a list of Type to control the output:</p>
  
  <pre><code>public static List&lt;Type&gt; ModelListSorted()
  {
      List&lt;Type&gt; modelListSorted = new List&lt;Type&gt;();
      modelListSorted.Add(typeof(UserRole));
      modelListSorted.Add(typeof(UserAccountRole));
      modelListSorted.Add(typeof(UserAccount));
      return modelListSorted;
  }
  </code></pre>
  
  <p>The problem is below where I cannot find a way to make it Work :-(</p>
  
  <pre><code>public static loopAllEntities()
  {
      List&lt;Type&gt; modelListSorted = ModelHelper.ModelListSorted();
  
      foreach (Type type in modelListSorted) 
      {           
          var records = ????? // get a list of records in the current table from type.
          foreach (var record in records)
          {
              // do something with the record
          } 
      }
  }
  </code></pre>