title: EF4 Unknown Column In Field List
body: <p>So, I am kind of stumped. I have been using a generic repository, and it works perfect. It sits on top of Entity Framework 4.1. I have used the same line of code to get a set of data numerous times and had no issues before. However, this one table in my database seems to be throwing an exception and I cannot for the life of me figure out how to fix it.</p>
  
  <p>This is the table design in the MySQL database</p>
  
  <pre><code>Completed
  =========
  CompletedId
  OldStepId
  NewStepId
  Name
  
  Step
  ====
  StepId
  Name
  Description
  </code></pre>
  
  <p>This is the model.cs definition</p>
  
  <pre><code>public class Completed
  {
      [Key]
      public int CompletedId { get; set; }
  
      public int OldStepId { get; set; }
      public int NewStepId { get; set; }
      public string Name { get; set; }
  
      public virtual Step OldStep { get; set; }
      public virtual Step NewStep { get; set; }
  }
  
  public class Step
  {
      [Key]
      public int StepId { get; set; }
  
      public string Name { get; set; }
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>The context definition</p>
  
  <pre><code>public DbSet&lt;Completed&gt; Completeds { get; set; }
  public DbSet&lt;Step&gt; Steps { get; set; }
  </code></pre>
  
  <p>The controller calling code in question</p>
  
  <pre><code>var completeds = new List&lt;Completed&gt;();
  using (var gm = new GenericRepo&lt;Completed&gt;())
  {
    completeds = gm.Get().ToList();
  }
  </code></pre>
  
  <p>The get method of the repository (simplified)</p>
  
  <pre><code>public IEnumerable&lt;T&gt; Get()
  {
   var context = new exampleContext();
   DbSet&lt;T&gt; dbSet = context.Set&lt;T&gt;();
   IQueryable&lt;T&gt; query = dbSet;
   return query.ToList();
  }
  </code></pre>
  
  <p>This is the error I get from the browser when navigating to the action</p>
  
  <pre><code>Unknown column 'Extent1.OldStep_StepId' in 'field list'
  </code></pre>
  
  <p>This is the inner exception obtained from the debugger</p>
  
  <pre><code>InnerException: MySql.Data.MySqlClient.MySqlException
     Message=Unknown column 'Extent1.OldStep_StepId' in 'field list'
     Source=MySql.Data
     ErrorCode=-2147467259
     Number=1054
     StackTrace:
          at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
          at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&amp; affectedRow, Int32&amp; insertedId)
          at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&amp; affectedRows, Int32&amp; insertedId)
          at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
          at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
          at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
          at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
          at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
          at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
  </code></pre>
  
  <p>This is the query which seems to have the issue from the debugger right before the error crashes the application</p>
  
  <pre><code>{SELECT
  `Extent1`.`CompletedId`, 
  `Extent1`.`OldStepId`, 
  `Extent1`.`NewStepId`, 
  `Extent1`.`Name`, 
  `Extent1`.`OldStep_StepId`, 
  `Extent1`.`NewStep_StepId`, 
  `Extent1`.`Step_StepId`, 
  `Extent1`.`Step_StepId1`
  FROM `Completed` AS `Extent1`}
  </code></pre>
  
  <p>Using reflection I was able to determine, or at least assume, that perhaps the reason StepId is not showing up as a field in Step is because Step is for whatever reason defined as Completed. This may not be the case. I am unsure why this error is occurring.</p>
  
  <p>Has anyone encountered something like this with the Entity Framework before? Is this an issue with my code somewhere? Is this an issue of the way the tables are connected? I have similar definitions to this setup which work flawlessly so I do not understand the discrepancy here.  The only difference between this table and all the others is that there are two references to the same object (Note: The Completed class holds two virtual Step objects). </p>
  
  <p>Also note: this is <strong>not</strong> EF Code First.</p>