实体框架抛出错误“无法计算表达式.不支持操作.未知错误:0x80070057." [英] Entity Framework is throwing an error "Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057."
问题描述
我正在使用实体框架来获取数据库数据.我写了一个动作以JSON格式返回表数据,如下所示:
I am using Entity Framework to get db data. I wrote an action to return table data in JSON format as below:
public JsonResult GetEmployeesData()
{
using (TrainingDBEntities db = new TrainingDBEntities())
{
return new JsonResult { Data = db.Employees, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
它没有抛出任何异常.但是出现控制台错误,错误代码为:500.当我调试时,它显示错误
It's not throwing any exception. But a console error is occurring with error code: 500. When I debugged, it showed an error
函数求值需要所有线程运行
The function evaluation requires all threads to run
当我尝试重新加载时,出现新错误:
When I try to reload, a new error occurs:
无法计算表达式.不支持操作.未知错误:0x80070057
Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057
我不知道这段代码有什么问题?
I don't have any idea what's wrong with this code?
推荐答案
解决方案是:
public JsonResult GetEmployeesData()
{
using (TrainingDBEntities db = new TrainingDBEntities())
{
var emps = db.Employees.ToList();
return new JsonResult { Data = emps, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
我认为在 JsonResult{} 中访问 db 会导致问题.
I think accessing db inside the JsonResult{} is causing the issue.
这篇关于实体框架抛出错误“无法计算表达式.不支持操作.未知错误:0x80070057."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!