-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的幫助... –