title: How can I fix "Invalid column name 'Discriminator'" Entity Framework Error
body: <p>I'm using EF 4.3 and I've been making some small changes to my entities, but none of the entity classes that are a part of this error.  I would like to understand why this started puking all of a sudden.</p>
  
  <p>My classes:</p>
  
  <pre><code>  public class Apple: Fruit
    {
        public Color Color{ get; set; }
    }
  
    public class Fruit: EntityBase
    {
        public int Size{ get; set; }
        public DateTime? DateGrown{ get; set; }
        public User GrownBy{ get; set; }
        public User SoldBy{ get; set; }
    }
  
   public class EntityBase
   {
        public int Id{ get; set;}
   }
  </code></pre>
  
  <p>The line that is now throwing <strong>"Invalid column name 'Discriminator'"</strong>: </p>
  
  <pre><code>repository.Apples.Include("GrownBy").Include("SoldBy")
            .Where(r =&gt; r.GrownBy.Id == user.Id 
             || r.SoldBy.Id == user.Id).ToList();
  </code></pre>
  
  <p>If I copy the SQL that repository.Apples is attempting to run, and run it in SSMS it runs just fine:</p>
  
  <pre><code>SELECT 
  [Extent1].[Id] AS [Id], 
  '0X0X' AS [C1], 
  [Extent1].[DateGrown] AS [DateGrown], 
  [Extent1].[Color] AS [Color], 
  [Extent1].[DateGrown] AS [DateGrown], 
  [Extent1].[GrownBy_Id] AS [GrownBy_Id], 
  [Extent1].[SoldBy_Id] AS [SoldBy_Id], 
  [Extent1].[Size] AS [Size], 
  FROM [dbo].[Fruits] AS [Extent1]
  WHERE [Extent1].[Discriminator] = N'Apple'
  </code></pre>
  
  <p>I tried adding the [NotMapped] Data Annotation as recommmended @ <a href="https://stackoverflow.com/questions/6553935/ef-code-first-invalid-column-name-discriminator-but-no-inheritance">EF Code First &quot;Invalid column name &#39;Discriminator&#39;&quot; but no inheritance</a>, like : </p>
  
  <pre><code>    [NotMapped]
      public class Apple: Fruit
      {
         public Color Color{ get; set; }
      }
  </code></pre>
  
  <p>but it creates a new error:</p>
  
  <blockquote>
    <p>The type 'Domain.Entities.Apple' was not mapped. Check that the type
    has not been explicitly excluded by using the Ignore method or
    NotMappedAttribute data annotation. Verify that the type was defined
    as a class, is not primitive, nested or generic, and does not inherit
    from EntityObject.</p>
  </blockquote>
  
  <p>on the following line:</p>
  
  <pre><code>       _context.Database.Initialize(true);
  </code></pre>
  
  <p>Really starting to regret using EF as it keeps popping up new issues like this every week it seems.  If anyone can provide any insight as to a fix, it would be greatly appreciated.</p>
  
  <p><strong>EDIT:</strong>
  So it looks like it has nothing to do with the Fruit or Apple entities at all.  I added an inherited class of the User entity and that's what is causing things to break.  </p>