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.
My classes:
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;}
}
The line that is now throwing "Invalid column name 'Discriminator'":
repository.Apples.Include("GrownBy").Include("SoldBy")
.Where(r => r.GrownBy.Id == user.Id
|| r.SoldBy.Id == user.Id).ToList();
If I copy the SQL that repository.Apples is attempting to run, and run it in SSMS it runs just fine:
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'
I tried adding the [NotMapped] Data Annotation as recommmended @ EF Code First "Invalid column name 'Discriminator'" but no inheritance, like :
[NotMapped]
public class Apple: Fruit
{
public Color Color{ get; set; }
}
but it creates a new error:
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.
on the following line:
_context.Database.Initialize(true);
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.
EDIT: 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.