Wrong select query generated with Entity Framework (mysterious extra column)
<p>I'm playing around trying to get a simple MVC website working. In it I am using a database and Entity Framework to communicate with it (as I have been doing for months on other projects).</p>

<p>Everything has been going fine up until I tried to retrieve from a specific table in my database. If I query that, the select that EF generates mysteriously contains a column that does not exists in that table (or any table in that database). This of course throws an exception complaining about the column not existing:</p>

<blockquote>
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'PerformerFolder_Id'.</p>
</blockquote>

<p>I've created a <code>UnitOfWork</code> object that uses the repository pattern to retrieve the data, and to make it as simple as possible, I exposed the <code>DataContext</code> so I could manually query that for testing:</p>

<pre><code>var test = loUnitOfWork.Context.Set&lt;DAL.File&gt;();
</code></pre>

<p>The <code>DAL.File</code> is a class generated by the POCO generator:</p>

<pre><code>public partial class File : BaseEntity
{
    public int Id { get; set; }
    public string FilePath { get; set; }
    public string FileName { get; set; }

    public virtual ICollection&lt;FilePerformer&gt; FilePerformerCollection { get; set; }
    public virtual ICollection&lt;FileProperty&gt; FilePropertyCollection { get; set; }

    public File()
    {
        FilePerformerCollection = new List&lt;FilePerformer&gt;();
        FilePropertyCollection = new List&lt;FileProperty&gt;();
        InitializePartial();
    }
    partial void InitializePartial();
}
</code></pre>

<p>I do have a <code>PerformerFolder</code> that has an <code>Id</code> column as the primary key, but that is in no way connected to the file table.</p>

<p>If I enable debug logging on the <code>DataContext</code> I see that it runs the following query:</p>

<pre><code>SELECT 
    [Extent1].[Id] AS [Id], 
    [Extent1].[FilePath] AS [FilePath], 
    [Extent1].[FileName] AS [FileName], 
    [Extent1].[PerformerFolder_Id] AS [PerformerFolder_Id]
    FROM [dbo].[File] AS [Extent1]
</code></pre>

<p>I've tried searching all file for "PerformerFolder" and other than the logical places (in the PerformerFolder class) it did not turn up anything. It seems to be generated based on something, but I just can't figure out what or where.</p>

<p>Does anyone have any suggestions?</p>