0

我是 EF Core 的新手,正在尝试将 TPH 继承与 Entity Framework Core 一起使用

我定义了以下类

    public class WorkItem {
        public Guid Id { get; set; }
        public string WorkItemType { get; set; }
        public string Description { get; set; }
    }
    public class Job : WorkItem {
        public string BillingNotes { get; set; }
    }

在我的上下文中,我有

    public class JobContextNew : DbContext {
        public virtual DbSet<WorkItem> WorkItem { get; set; }
        public virtual DbSet<Job> Job { get; set; }

        public JobContextNew(DbContextOptions<JobContextNew> options) : base(options) { }

        protected override void OnModelCreating(ModelBuilder modelBuilder) {
            modelBuilder.Entity<WorkItem>(entity => entity.Property(e => e.Id).ValueGeneratedNever());
            modelBuilder.Entity<WorkItem>()
                .HasDiscriminator(workitem => workitem.WorkItemType)
                .HasValue<Job>(nameof(Job));
        }
    }

如果我在 Job 中省略该字段,它会很好地提取数据,但是当我重新添加 BillngNotes 时,我收到以下错误:Invalid column name 'BillingNotes

谁能告诉我我可能做错了什么?

4

0 回答 0