目前,我使用Code First(来自现有数据库)策略开发了一个应用程序。我有一个关于EF6关系注释的问题。这是我的User
课程:
public partial class User
{
public User() { }
[Key]
public int id { get; set; }
[Required]
[StringLength(64)]
public string identity { get; set; }
[Required]
[StringLength(16)]
public string sales_office_code { get; set; }
[ForeignKey("sales_office_code")]
public virtual Office Office { get; set; }
}
这是我的Office
课程:
public partial class Office
{
public Office ()
{
Users = new List<User>();
}
[Key]
public int id { get; set; }
[Required]
[StringLength(16)]
public string code { get; set; }
[Required]
[StringLength(128)]
public string name { get; set; }
public virtual ICollection<User> Users { get; set; }
}
默认情况下,EF6会将User.sales_office_code
映射到Office.id
。如何更改此行为,以便将User.sales_office_code
映射到Office.code
?