title: Dynamically get a DbSet
body: <p>I want to get a <code>DbSet</code> with the class name that I have stored in a variable.</p>
  
  <p>I have tried with this code:</p>
  
  <pre><code>string name = "ParosLineas";
  var dbset = (System.Data.Entity.DbSet)efContext.GetType().GetProperty(name).GetValue(efContext);
  
  dbset.AddRange(dates.[name]);
  efContext.SaveChanges();
  </code></pre>
  
  <p>but I get this error:</p>
  
  <blockquote>
    <p>System.InvalidCastException: 'Unable to cast object of type 'System.Data.Entity.DbSet1[Report.Models.ParosLinea]' to type 'System.Data.Entity.DbSet'</p>
  </blockquote>
  
  <p>this is my ParosLine declaration:
  <a href="https://i.stack.imgur.com/oONOv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oONOv.png" alt="enter image description here"></a></p>