C# 映射到表c时的类继承#

C# 映射到表c时的类继承#,c#,class,inheritance,C#,Class,Inheritance,当一个类映射到数据库中的表时,是否可以创建类继承?我试图将这些类用于不同的方法,我只想显示我需要的信息 我收到此错误“消息”:“错误”。“例外消息”:“列名“鉴别器”无效。”,“例外类型”:“System.Data.SqlClient.SqlException” 使用系统; 使用System.Collections.Generic; 使用System.ComponentModel.DataAnnotations; 使用System.ComponentModel.DataAnnotations.S

当一个类映射到数据库中的表时,是否可以创建类继承?我试图将这些类用于不同的方法,我只想显示我需要的信息

我收到此错误“消息”:“错误”。“例外消息”:“列名“鉴别器”无效。”,“例外类型”:“System.Data.SqlClient.SqlException”

使用系统;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.ComponentModel.DataAnnotations.Schema;
名称空间:project.Models
{
[表格(“VOU用户”)]
公务舱头等舱
{
[关键]
公共Int64 id{get;set;}
公共字符串标题{get;set;}
公共字符串post{get;set;}
}
公共舱二等舱:头等舱
{
公共字符串状态{get;set;}
公共Int32?代码{get;set;}
公共Int32?公司{get;set;}
公共字符串标志_已批准{get;set;}
[外键(“IdExample”)]
公共虚拟ICollection示例{get;set;}
}
}
“消息”:“错误”, “例外信息”:“列名‘鉴别器’无válido。”,
“ExceptionType”:“System.Data.SqlClient.SqlException”

假设您使用的是EF6,您应该阅读以下文章


这里的内容实在太多,无法包含整个教程,但这里重要的部分是EF设计器允许您指定鉴别器,以决定表行映射到继承链中的对象类型。

这里的问题到底是什么?@logix问题是,我在尝试获取数据时出错……这是web api项目的一部分。。。。“InnerException”:{“Message”:“Error.”,“ExceptionMessage”:“列名'Discriminator'无效。”,“ExceptionType”:“System.Data.SqlClient.SqlException”,明显的问题是数据库中是否存在此属性。我建议您遵循教程。您没有名为“Discriminator”的属性.所以我想你的问题出在别的地方了。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;


namespace Someproject.Models
{

    [Table("Vo_User")]
    public class FirstClass
    {
        [Key]
        public Int64 id { get; set; }
        public string title { get; set; }
        public string post { get; set; }
    }

    public class SecondClass : FirstClass
    {
        public string State { get; set; }
        public Int32? Code { get; set; }
        public Int32? Company { get; set; }
        public string Flag_Approved { get; set; }

        [ForeignKey("IdExample")]
        public virtual ICollection<ExampleClass> Example { get; set; }
    }

}