所以我遇到此错误:
"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; }
}
对员工的请求无误运行,只有过程表出错。我希望有人明白这是怎么回事。
非常感谢您的帮助
编辑:
流程表中的“提交者”列应链接到“员工”表中的mavnr
答案 0 :(得分:0)
正如@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; }
}