我得到一个错误在我的mvc应用程序。我试图显示记录从我的sql表使用实体框架。这是我正在尝试的代码。但是我不知道为什么这段代码给我错误
这是我的模型
[Table("tbInsertMobile")]
public class tbInsertMobile
{
[Key]
public int MobileID { get; set; }
public string MobileName { get; set; }
public string MobileIMEno { get; set; }
public string mobileprice { get; set; }
public string mobileManufacured { get; set; }
}
my another class in model
public class EmployeeContext:DbContext
{
public DbSet<tbInsertMobile> usermobiles { get; set; }
}
这是我的控制器代码
public ActionResult Index(int id)
{
EmployeeContext employeeContext = new EmployeeContext();
tbInsertMobile employee = employeeContext.usermobiles.Single(x => x.MobileID == id);
return View(employee);
}
现在我得到的错误是这个
The 'MobileID' property on 'tbInsertMobile' could not be set to a 'System.Int64' value. You must set this property to a non-null value of type 'System.Int32
专家告诉我我从哪里得到这个错误由于
答案已经在评论中了。
It's trying to assign a long to an int. Change MobileID to be long. – CodeCaster