title: Database explorer tool for SQL Server 2012 using Entity Framework
body: <p>I am tasked with creating a database explorer tool for SQL Server 2012 databases using Entity Framework and ASP.NET MVC.</p>
  
  <p>I have created required db contexts and I am able to get static queries to work. The current approach is very inefficient as it involves creating a controller action and a view for every table - this is for columns in tables etc.</p>
  
  <p>I wish to have only one controller action and only one view to render paged records of tables. </p>
  
  <p>I am able to get table names displayed using reflection on db context. 
  The code I use is very simple: </p>
  
  <pre><code>foreach (var propertyInfo in db.GetType().GetProperties())
  {
  //every property here is a persisted entity
  
  }
  </code></pre>
  
  <p>However I am not able to get records from the db context db set. </p>
  
  <p>My design involves passing table name (Entity Framework entity name) as query string parameter.
  e.g.</p>
  
  <blockquote>
    <p><a href="http://localhost:8080/TableDetails/List?id=MyNamespace.Models.User_Info" rel="nofollow">http://localhost:8080/TableDetails/List?id=MyNamespace.Models.User_Info</a></p>
  </blockquote>
  
  <p>The corresponding List Action method is:</p>
  
  <pre><code>public ActionResult List(string id)
  {   
      ViewBag.TableName = id;
      //here I need to put up code to get first page of the table user_info
      return View(); 
  }
  </code></pre>
  
  <p>The static List Action method would be:</p>
  
  <pre><code>    public ActionResult List(string id)
      {
          var rowsPerPage = 20;
          int? page = 1;
          var skipCount = rowsPerPage * (page ?? 0);
          var vm = new ViewModel&lt;user_info&gt;();
          vm.RowsPerPage = rowsPerPage;
          vm.Records = db.user_info.OrderByDescending(x =&gt; x.update_date).Skip(skipCount).Take(rowsPerPage).ToList();
          vm.CurrentPageNo = page ?? 1;
          vm.HasNextPage = db.user_info.OrderByDescending(x =&gt; x.update_date).Skip(skipCount + rowsPerPage).Take(1).ToList().Count &gt; 0;
          return View(vm);
      }
  </code></pre>
  
  <p>Is there a way of querying Entity Framework context dynamically ? </p>