实体框架抛出错误“无法评估表达式.不支持该操作.未知错误:0x80070057. [英] Entity Framework is throwing an error "Unable to evaluate the expression. Operation not supported. Unknown error: 0x80070057."

查看:90
本文介绍了实体框架抛出错误“无法评估表达式.不支持该操作.未知错误:0x80070057.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework获取数据库数据.我编写了一个操作以返回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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆