EntityFramework6 - 错误 42703:未找到列 Extent1...

EntityFramework6 - Error 42703: column Extent1... not found

所以我遇到了这个错误:

"ExceptionMessage": "42703: column Extent1.Employee_mavnr does not exist"

经过一些 Google 搜索,我仍然无法找出确切的问题所在。我发现的大多数解释都是关于列名的,我现在已经对它们进行了多次更改,但仍然无法正常工作。

我的数据库是这样的

CREATE TABLE tbl_process
(
  id integer NOT NULL DEFAULT nextval('"Process_Id_seq"'::regclass),
  name text,
  description text,
  submitter text,
  created date,
  CONSTRAINT "PrimaryKey-ID" PRIMARY KEY (id)
)
CREATE TABLE v_employee
(
  mavnr text NOT NULL, -- Mitarbeiter Nummer
  vorname text,
  nachname text,
  abt text,
  email text,
  del boolean,
  CONSTRAINT employee_pkey PRIMARY KEY (mavnr)
)

我当前生成此错误的模型如下所示:

 [Table("tbl_process", Schema = "public")]
    public class Process
    {
        [Key]
        public int id { get; set; }

        public string name { get; set; }

        public string description { get; set; }

        public DateTime created { get; set; }

        public string submitter { get; set; }

        public virtual Employee Employee { get; set; }
    }


    [Table("v_employee", Schema = "public")]
    public class Employee
    {
        [Key]
        public string mavnr { get; set; }

        public string vorname { get; set; }

        public string nachname { get; set; }

        public string abt { get; set; }

        public string email { get; set; }

        public bool del { get; set; }
    }

员工请求没有任何错误地运行,只有进程 Table 出错。我希望有人看到它有什么问题。

感谢您的帮助,非常感谢

编辑:

流程table中的提交者列应该link从员工table

到mavnr

正如@DavidG 在上面的评论中所说,您有一个导航 属性 但没有用于该导航的外键 属性。

您需要添加外键属性并用[ForeignKey("keyname")]属性标记导航属性:

[Table("tbl_process", Schema = "public")]
public class Process
{
    [Key]
    public int id { get; set; }

    public string name { get; set; }

    public string description { get; set; }

    public DateTime created { get; set; }

    public string submitter { get; set; }

    public string mavnr { get; set; } // <-- add this foreign key

    [ForeignKey("mavnr")] // <-- decorate the navigation property like this (or is "submitter" your FK?)
    public virtual Employee Employee { get; set; }
}


[Table("v_employee", Schema = "public")]
public class Employee
{
    [Key]
    public string mavnr { get; set; }

    public string vorname { get; set; }

    public string nachname { get; set; }

    public string abt { get; set; }

    public string email { get; set; }

    public bool del { get; set; }
}