【发布时间】:2012-12-04 14:55:49
【问题描述】:
我有两个模型类:出勤和员工。我已将 Employee 类定义为:
public class Employee
{
public int Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
然后我将出勤类定义为:
public class Attendance
{
public int Id { get; set; }
public Employee Employee { get; set; } //This is the foreign key
public DateTime LoginDate { get; set; }
public DateTime LogoutDate { get; set; }
}
当我尝试将数据插入 Employee 表时,它工作正常,但是当我尝试在出勤表中插入数据时,它显示异常。我正在正确检查员工并在出勤表中仅插入一行员工。
这是异常的图像:
【问题讨论】:
-
什么是内部异常(根据主要异常的说明)。另外,您如何创建和保存出勤对象? (显示示例)。
标签: c# .net entity-framework ef-code-first