嗨,我有两个用于技术人员和专业的模型类我通过创建专业外键列与表建立关系当我将此模型映射到 SqlReader 以进行插入函数时,我想使用该外键列创建 Dropdownlist 我有错误,例如不能隐式将 int 转换为 model.profession。
型号代码:
public class Technician
{
[ScaffoldColumn (false)]
public int Id { get; set; }
[Required]
[Display(Name = "Name")]
public string Name { get; set; }
[Required]
public Profession Profession { get; set; }
}
public class Profession
{
[Key]
public int ProfessionId { get; set; }
public string ProfessionType { get; set; }
}
Db类代码:
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Technician technician = new Technician();
technician.Id = Convert.ToInt32(dr["techId"]);
technician.Name = dr["techName"].ToString();
technician.Profession = Convert.ToInt32(dr["primeProfessionId"]);
Jobtechnicians.Add(technician);`
}