我为用户表提供了一个类实体:
[Table("Users", Schema = "Membership")]
public class User
{
public User()
{
}
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
[Required]
[StringLength(450)]
[Index(IsUnique = true)]
public string Username { get; set; }
[Required]
public string Password { get; set; }
[Required]
public string Email { get; set; }
public int? StateID { get; set; }
[ForeignKey("StateID")]
public virtual Place.State State { get; set; }
}
并且与课程状态有关
[Table("States", Schema = "Place")]
public class State
{
public State()
{
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
[Required(ErrorMessage = "Please enter name")]
public string Name { get; set; }
}
但是在更新数据库后,我看到添加了新的额外键State_Id,我的外键在代码中定义了StateID,但是您可以看到最终表在表数据库中有2个外键。