簡體   English   中英

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; }
    }

對員工的請求運行無誤,只有流程表在出錯。 我希望有人明白這是怎么回事。

感謝您的幫助,非常感謝

編輯:

流程表中的Submitter列應鏈接到employee表中的mavnr

正如@DavidG在上面的評論中所說,您具有導航屬性,但沒有用於該導航的外鍵屬性。

您需要添加FK屬性,並使用[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; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM