关键错误点Unable to cast object of type 'System.Int32' to type 'System.String'.提示是无法将“System.Int32”的对象强制转换为“System.String”。于是我就找了所有使用Int的地方,终于发现

/// <summary>
     /// ID
     /// </summary>
     [Key]
     [StringLength(20)]
 [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
 public override int ID { get; set; }

在一个基类中有个Int类型的ID,不小心加上了StringLength属性。int类型是不能添加StringLength属性的,去掉之后就可以正常访问了。