我有两个表和对应于每个表的模型: Employee 和 EmployeeEducation 在 EmployeeEducation 我有来自表 Employee 的 2 个外键:顾问的 ID 和拥有教育的实际员工的 ID。每个教育可以有不同的顾问。
[Required(ErrorMessage = "Contact Admin")]
[Display(Name = "Consultant")]
public int? ConsultantId { get; set; }
*emphasized text*
[Required(ErrorMessage = "Contact Admin")]
public int? EmployeeId { get; set; }
对于每个 id,我都有这些对象可以到达对象
[ForeignKey("EmployeeId")]
public virtual Employee Employee { get; set; }
[ForeignKey("ConsultantId")]
public virtual Employee Consultant { get; set; }
当我运行代码并尝试通过顾问对员工进行教育时,它给了我以下异常和内部异常。
EntityCommandExecutionException
{"An error occurred while executing the command definition. See the inner exception for details."}
Inner exception: SqlCeException
{"The column name is not valid. [ Node name (if any) = Extent1,Column name = Employee_Id ]"}
但是当我删除顾问对象时,它不会给出异常。我该如何解决这个问题,以便我可以同时访问顾问和员工本身?
异常发生在 DetailsEducation.cshtml 中:
@{ if (Model.EducationList == null || !Model.EducationList.Any())
{
以下是 EducationList 的填充方式:
public ActionResult DetailsEducation(int id)
{
Employee employee = _work.EmployeeRepository.GetSet()
.Include(a => a.EducationList)
.Include(a => a.EducationList.Select(c => c.University))
.Include(a => a.EducationList.Select(c => c.Department))
.FirstOrDefault(a => a.Id == id);
return PartialView("_DetailsEducation", employee);
}