【发布时间】:2015-02-10 07:41:54
【问题描述】:
我有两个模型类,一个是ApplicationUser,第二个是Appointment。应用程序用户包括使用该应用程序的所有用户,在我的例子中是医生和数据输入操作员。医生将被分配到每个预约,数据输入操作员将把这个日志记录到数据库中。我想用约会映射这两个用户。我已经尝试过这样的事情
public class Appointment
{
public int AppointmentID { get; set; }
public DateTime Date { get; set; }
public int DoctorID { get; set; }
[ForeignKey("DoctorID")]
public virtual ApplicationUser Doctor { get; set; }
public int SystemUserID { get; set; }
public virtual ApplicationUser SystemUser { get; set; }
}
public class ApplicationUser : IdentityUser
{
public string Email { get; set; }
public string Mobile { get; set; }
public string FirstNsme { get; set; }
public string LastName { get; set; }
}
但这会引发错误
Appointment_Doctor_Target_Appointment_Doctor_Source: : 引用约束的Dependent Role 中所有属性的类型必须与Principal Role 中对应的属性类型相同。实体“Appointment”上的属性“DoctorID”类型与引用约束“Appointment_Doctor”中实体“ApplicationUser”上的属性“Id”类型不匹配。
谁能指出为什么会出现这个错误以及解决这个问题的正确方法是什么?
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework