-1
请任何人都可以帮助我! 我有一个名为:学生的模型类。 现在我需要用“StudentID”保存用户。 “StudentID”将作为外键保存在用户表中。 这里是我的学生类如何在mvc5中的AspNetUsers中添加外键引用
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public int? DepID { get; set; }
public DateTime EnrollmentDate { get; set; }
[ForeignKey("DepID")]
public virtual Department Department { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
和我的身份模型
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<Student> Students { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<Department> Departments { get; set; }
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
所以我怎样才能添加“studentID”进入用户表的外键。
对不起!我想你没有得到它。如何在用户表中使用学生ID作为外键? –
通过“用户表”你指的是Asp.Net身份表用户? – ChrisRun
对不起!我想使用StudenID作为用户表中的外键。 PLZ的帮助... –