title: C# Linq using variable for Model
body: <p>Trying to write a piece of code that is dynamic in that it can accept any number of possible model definitions.</p>
  
  <p>Current hard code is:</p>
  
  <pre><code>var items = _context.Events.ToList();
  
  foreach (var item in items)
  {
       (...)
  }
  </code></pre>
  
  <p>What I would like to do is to make the <code>_context.Events.ToList();</code> be more like <code>_context.{variable that holds model name}.ToList();</code></p>
  
  <p>Something like:</p>
  
  <pre><code>var modelName = "Table1"
  var items = _context.modelName.ToList();
  
  foreach (var item in items)
  {
       (...)
  }
  </code></pre>
  
  <p>I thought about declaring items as a generic variable, that way it was available to the entire method even if set inside an if or switch, but no idea on what to declare it as.</p>
  
  <p>Is something like this possible?</p>