Reprinted: https://blog.csdn.net/lanse_my/article/details/38128355
I ran into an error the other day using code first: The column name 'Discriminator' is invalid. This is a rare error, and after searching for a long time, I found that it is an inheritance problem of the code first poco entity object.
For example, I define an entity class that corresponds to the Project table of the database :
string Name { get ; set ; } |
Later, a subclass ChildProject was defined to inherit from it, but the subclass does not correspond to any table in the database
public class ChildProject : Project |
So every time EF's Context accesses Project or ChildProject, an error occurs: the column name 'Discriminator' is invalid.
Solution: The subclass does not map to any database, just add an unmapped attribute [NotMapped].
public class ChildProject : Project |