title: MVC 3, C# - invalid column name generated by code
body: <p>I am new to asp.net C# and trying to learn by building a simple web app based on MVC 3 Music application. So far i have had a decent run but i am running into this this and i am not able to figure out the root cause. plz help</p>
  
  <p>I am building a simple website where Projects are listed, then clicking on projects you see all the tables and then clicking on table you see all the columns. Projects/Tables/Column are being fetched from SQL db which has valid data and PK/FK keys defined. i am able to navigate from projects to tables and can see all columns under tables but when I click on column link, i get error as described below.</p>
  
  <p>ERROR: "Invalid column name 'Tables_Id'."  SQL profiler shows this column in the query but i do not understand where is it coming from as I do not have any such columm.</p>
  
  <p>CONTROLLER CLASS</p>
  
  <pre><code>public class ProjectController : Controller  // Inherit from base class Controller
  {
      DbEntities storeDB = new DbEntities();   //Create Object/instance of class //StorDB is  reference to an object
  
      public ActionResult Index()
      {
          var Name = storeDB.ProjectNM.ToList(); //Use 'var' coz we may have any type returned, 'var' is determined at run time
          return View(Name); 
      }
  
      public ActionResult BrowseTables(string Projects) 
      {
          var ProjectModel = storeDB.ProjectNM.Include ("Tabless")
          .Single(g =&gt; g.Name == Projects);
  
          return View(ProjectModel);
      }
  
      public ActionResult BrowseColumns(string TableIs)
      {
          var ProjectModel1 = storeDB.TableNM.Include("Columnss")
          .Single(g =&gt; g.Tbl_Name == TableIs);
  
          return View(ProjectModel1);
  
          //var ColumnModel = storeDB.TableNM.Find(TableIs);
         // return View(ColumnModel);
  
      }
  }
  </code></pre>
  
  <p>Other Classes</p>
  
  <pre><code>public partial class Projects //Partial class, see comment below
  {
      public int Id { get; set; }
      public string Name { get; set; }
  
      public List&lt;Tables&gt; Tabless { get; set; }  //Navigation Property, required so that we can include tables under projects
  
  }
  
  public class Tables
  {
      public int Id { get; set; }
      public int ProjectId { get; set; }
      public string Tbl_Name { get; set; }
      public Projects Project { get; set; }   //Class table can have (belong) only one project
  
      public List&lt;Columns&gt; Columnss { get; set; } //Table can have more than one column
    }
  
   public class Columns
  {
      public int Id { get; set; }
      [ForeignKey("Tables")] 
      public int TblId { get; set; }
      public string Column_Name { get; set; }
      public string IncludeFlag { get; set; }
    }
  </code></pre>
  
  <p>View </p>
  
  <pre><code>&lt;ul&gt; 
  @foreach (var Tables in Model.Tabless) 
  { 
      &lt;li&gt; 
        @Html.ActionLink(Tables.Tbl_Name, "BrowseColumns", new { TableIs = Tables.Tbl_Name }) 
      &lt;/li&gt; 
  } 
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <p>Query from SQL profiler</p>
  
  <pre><code>[Project2].[Tables_Id] AS [Tables_Id]
  </code></pre>
  
  <p>As you can seethe query has a column  [Tables_Id] and I do nto understand why it is there as i do nto have any such column. Please help!</p>