title: EF get dbset name in runtime from Type
body: <p>Purpose:
  I need to get the name of the dbset name of the entity
  typeof(UserAccount) = "UserAccounts".
  But in runtime I need a common type for the loop and therefor do not know example "UserAccount".
  Only the "name" from typeof?</p>
  
  <p>I have created an DbContext with some entities.
  I have been googling for some time but it do not seem to be working for me because of the Type converting?</p>
  
  <p>Please see my method <strong>GetDbSetName</strong> in the bottom of this description.</p>
  
  <p>I am pretty new at this EF stuff - so please help med with my issue as described below ;-)</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 using <strong>Type</strong> - If I use "UserAccount" it Works and I get "UserAccounts".
  But I do not have the "UserAccount" in runtime as I am in a loop with a serie of types.
  I do only have the Type list giving the e</p>
  
  <pre><code>public static loopList()
  {
      List&lt;Type&gt; modelListSorted = ModelListSorted();
      foreach (Type currentType in modelListSorted)
      {
           string s = DataHelper.GetDbSetName(currentType, db);
      } 
  }
  </code></pre>
  
  <p><strong>HERE IS THE METHOD GIVING ME THE CHALLANGES ;-)</strong>
  Meaning not compiling.
  saying I am missing a assembly?
  I know it is pretty pseudo but can this be done smoothly?</p>
  
  <pre><code>public static string GetDbSetName(Type parmType, MyEntities db)
  {
      string dbsetname = (db as IObjectContextAdapter).ObjectContext.CreateObjectSet&lt;parmType&gt;().EntitySet.Name;
      return dbsetname;
  }
  </code></pre>