我有两个简单的类,主键和FK关系。
在Sub_Department类中,我收到错误
SqlException:列名称无效' DepartmentID1'。 System.Data.SqlClient.SqlCommand +<> c.b__108_0(任务结果)
这是我的代码
public class Departments_Category_Registration
{
[Key]
public int CategoryID { get; set; } // This is the PK
public Departments DepartmentID { get; set; } // this is a FK
和我的Departments类使用PK
public class Departments
{
[Key]
public int DepartmentID { get; set; }
[Display(Name ="Departments")]
[Required]
public string Department_Name { get; set; }
[Display(Name ="Departments")]
[Required]
public string Description_Long { get; set; }
[Display(Name ="Short Description_Short")]
[Required]
public string Description_Short { get; set; }
public bool IsEnabled { get; set; }
}
但是,如果我更新我的数据库以将FK更改为department1它有效,有趣的是我从未在我的代码中使用过1,我已将其从ID更改为DepartmentID(如果有帮助)
其次,我想我问,是否明智地为每个模型创建一个单独的控制器?
EHI