[英]Entity Framework - Code first from database “invalid column name 'discriminator'”
I wanna ask about "invalid column name 'discriminator'". 我想问一下“无效的列名'discriminator'”。
I'm trying to access data using, for example, db.[Table-Name].ToList()
. 我正在尝试使用db.[Table-Name].ToList()
访问数据。 I generated my model using Entity Framework code first from database and when I try to access the table data it gives me the mentioned error. 我首先使用Entity Framework代码从数据库中生成了模型,当我尝试访问表数据时,它给了我提到的错误。
The general reason: 一般原因:
The Database field and entity class field inconsistencies caused if you have an entity class mapped to entity framework, and you add another class to your project that inherits from that class, it may break Entity Framework. 如果您有一个映射到实体框架的实体类,并且您向您的项目中添加了另一个继承自该类的类,则会导致数据库字段和实体类字段不一致。 You could mark the child class as [NotMapped] so that EF doesn't try to include it in the map. 您可以将子类标记为[NotMapped],以便EF不会尝试将其包含在地图中。 This also means you won't be able to use it in EF queries. 这也意味着您将无法在EF查询中使用它。
You might get help from the following post. 您可能会从以下帖子中获得帮助。 EF Code First "Invalid column name 'Discriminator'" but no inheritance EF代码第一个“无效的列名'Discriminator'”,但没有继承
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.