所以我有两种模式,一种是公司,一种是省。
[Table("Company")]
public class Company {
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string Name { get; set; }
public int ProvinceID { get; set; }
public ProvinceModel Province{
get {
// ????
}
}
}
public class CompanyContext : MyXsiteContext {
public DbSet<Company> Companies { get; set; }
}
这是我的省份:
[Table("Province")]
public class ProvinceModel {
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public string Name { get; set; }
}
public class ProvinceContext : MyXsiteContext {
public DbSet<ProvinceModel> Provinces { get; set; }
}
如何让仅保存 ProvinceID 的公司引用 Province 对象,以便在我的视图中引用 Province.name?