简体   繁体   English

"具有继承的 EF Core 错误无效列“鉴别器”"

[英]EF Core error invalid column "discriminator" with inheritance

I'm new to EF Core and sorry if this is a stupid question.我是 EF Core 的新手,如果这是一个愚蠢的问题,我很抱歉。 I'm getting the Invalid Column "Discriminator" when I try to query当我尝试查询时,我得到了无效的列“鉴别器”

Context.EmployeeAddressNavigation.where(x =>x.Name.Contains("name")).Select(x => new {x.Id,x.employAddress})

When there is inheritance hierarchy in your model you must specify discriminator.Like this当您的模型中有继承层次结构时,您必须指定鉴别器。像这样

modelBuilder.Entity<Employee>()
            .HasDiscriminator<string>("EmployeeType");

To read more about discriminator,see The Fluent API HasDiscriminator Method要阅读有关鉴别器的更多信息,请参阅Fluent API HasDiscriminator 方法

I had the same issue and I thought it was a column named "discriminator" which I dont have.我有同样的问题,我认为这是一个名为“鉴别器”的列,我没有。 Using [NotMapped] on the child worked.对孩子使用[NotMapped]有效。

[NotMapped]
public class EmployeeAddressNavigation : Employee
{
   public EmpoyeeAddress employAddress {get;set;}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM