我在asp.net mvc中编写了代码,以使用实体框架访问数据,但是在执行过程中出现了类似错误
System.Data.Entity.dll中发生类型'System.Data.EntityException'的异常,但未在用户代码中处理 附加信息:基础提供程序在打开时失败。发生
//Controller
public class EmployeeController : Controller
{
// GET: Employee
public ActionResult Details(int id)
{
EmployeeContext employeecontext = new EmployeeContext();
Employee employee = employeecontext.EmployeeDetails.Single(emp => emp.EmployeeID == id);
return View(employee);
}
}
//模型雇员
[Table("tblEmployee")]
public class Employee
{
[Key]
public int EmployeeID { get; set; }
public string Name { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
}
//Model Employee Context
public class EmployeeContext : DbContext
{
public DbSet<Employee> EmployeeDetails { get; set; }
}
System.Data.Entity.dll中发生类型'System.Data.EntityException'的异常,但未在用户代码中处理 附加信息:基础提供程序在打开时失败。发生