实体框架抛出错误“无法计算表达式。不支持操作。未知错误:0x80070057。”

Siv*_*ula 5 c# entity-framework asp.net-mvc-4

我正在使用实体框架来获取数据库数据。我写了一个动作以 JSON 格式返回表数据,如下所示:

public JsonResult GetEmployeesData()
{
     using (TrainingDBEntities db = new TrainingDBEntities())
     {
           return new JsonResult { Data = db.Employees, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
     }
}
Run Code Online (Sandbox Code Playgroud)

它没有抛出任何异常。但是出现控制台错误,错误代码为:500。当我调试时,它显示了一个错误

函数求值需要所有线程运行

当我尝试重新加载时,出现新错误:

无法计算表达式。不支持操作。未知错误:0x80070057

我不知道这段代码有什么问题?

Siv*_*ula 4

解决方案是:

public JsonResult GetEmployeesData()
{
     using (TrainingDBEntities db = new TrainingDBEntities())
     {
           var emps = db.Employees.ToList();
           return new JsonResult { Data = emps, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
     }
}
Run Code Online (Sandbox Code Playgroud)

我认为访问 JsonResult{} 内的数据库导致了问题。