我有一个名为EnrollTrainee的表。我的 EnrollTrainee 模型类中有这些列:
[Key]
public int id { get; set; }
public int TraineeID { get; set; }
public int TrainerID { ![enter image description here][1]get; set; }
public virtual CreateUsers user_userid { get; set; }
public virtual CreateUsers user_id { get; set; }
public DateTime dt { get; set; }
这两个列TraineeID和TrainerID将与表CreateUser中的User_id列进行映射。
这是CreateUser模型类
public class CreateUsers
{
[Key]
public int User_Userid { get; set; }
[Required]
[Display(Name="Enter User Name")]
public string User_name { get; set; }
[Required]
[Remote("IsDomainIDExist", "Account", ErrorMessage = "Domain ID Already Exist")]
[Display(Name = "Enter Domain ID")]
public string User_username { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Enter Password")]
public string User_password { get; set; }
[Required]
[Display(Name = "Enter Department")]
public string User_department { get; set; }
[Required]
[Remote("IsEmployeeIDExist", "Account", ErrorMessage = "Domain ID Already Exist")]
[Display(Name = "Enter Employee ID")]
public string User_employeeid { get; set; }
[Required]
[Display(Name="Select Role Type")]
public int RoleID { get; set; }
[Display(Name="Enable?")]
public bool User_Enable { get; set; }
[DataType(DataType.DateTime)]
[Display(Name = "Date Time")]
public DateTime dt { get; set; }
public virtual RoleModel Role { get; set; }
}
如何在 EF CF 中映射两个具有相同主键的外键?