EF实体生成关系导致相互循环取数据出现异常"Self referencing loop detected for property "

异常信息:

Self referencing loop detected for property ‘md_agent‘ with type ‘System.Data.Entity.DynamicProxies.md_agent_5F7CB7C257B9164D0D18D2B3E8DA3838A3ED1C7F5D326A56B71D51234B89C401‘. Path ‘[1].md_design[0]‘.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Serialize(TextWriter textWriter, Object value)
   at Ninesky.Core.Serialization.JsonNetResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<>c__DisplayClass28.<BeginInvokeAction>b__19()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult)

解决方法:直接從 Entity Framework 模型 (EDMX) 移除不必要的關聯屬性,以避免發生參考循環的狀況。

时间: 2024-10-07 13:39:22

EF实体生成关系导致相互循环取数据出现异常"Self referencing loop detected for property "的相关文章

EF关于报错Self referencing loop detected with type的原因以及解决办法

1)具体报错 { "Message": "出现错误.", "ExceptionMessage": ""ObjectContent`1"类型未能序列化内容类型"application/json; charset=utf-8"的响应正文.", "ExceptionType": "System.InvalidOperationException", &q

如何让vs2017 EF实体生成支持Mysql 和 Oracle?

1.Mysql 安装   MySql Connector/Net        https://dev.mysql.com/downloads/connector/net/ 安装    mysql for visualstudio         https://dev.mysql.com/downloads/windows/visualstudio/ 安装时entity framwork相关的选项一定要选. 如果还不行的话执行一下 .\devenv.exe /setup 项目中 添加最新版本M

python locust 性能测试:locust 参数化(list) ---循环取数据,数据可重复使用

from locust import TaskSet, task, HttpLocust class UserBehavior(TaskSet): def on_start(self): # 当模拟用户开始执行TaskSet类的时候,on_start方法会被调用 self.index = 0 @task def test_visit(self): url = self.locust.share_data[ self.index] # 取 self.locust.share_data<等于 Web

python locust 性能测试:locust参数-保证并发测试数据唯一性,循环取数据

from locust import TaskSet, task, HttpLocustimport queue class UserBehavior(TaskSet): @task def test_register(self): try: # get_nowait() 取不到数据直接崩溃:get() 取不到数据会一直等待 data = self.locust.user_data_queue.get_nowait() # 取值顺序 'username': 'test0000'.'usernam

python locust 性能测试:locsut参数化-保证并发测试数据唯一性,不循环取数据

from locust import TaskSet, task, HttpLocustimport queue class UserBehavior(TaskSet): @task def test_register(self): try: # get_nowait() 取不到数据直接崩溃:get() 取不到数据会一直等待 data = self.locust.user_data_queue.get_nowait() # 取值顺序 'username': 'test0000'.'usernam

如何在后台动态生成ASPxCheckBoxList标签并循环(数据调用存储过程)

1 DataTable dt_attrname = new DataTable(); 2 DataTable dt_valuename = new DataTable(); 3 dt_valuename = goodsmanagebll.Get_AdminGetAttributeListandValues(_cateid).Tables[0]; //属性值 4 dt_attrname = goodsmanagebll.Get_AdminGetAttributeListandValues(_cat

jq循环取数据 ,一直记不住,放到这

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <title>首页</title> <l

ef entity转json引起的Self referencing loop

问题简介:前段时间做项目时,将取到的entity往Redis cache里存放时报多重引用的错误. Self referencing loop detected for property 'CheckItemCategory' with type. 一.问题详情 1.chectItemCategory与CheckItem实体介绍 2.我们用ef取了List<CheckItemCategory>,以Json的形式存放到redis中.但在JsonConvert.SerializeObject时报多

PHP无限循环取MySQL中的数据。

最近公司有个需求需要从MySQL获取数据,然后在页面上无线循环的翻页展示.主要就是一直点击一个按钮,然后数据从最开始循环到末尾,如果末尾的数据不够了,那么从数据的最开始取几条补充上来. 其实,这个功能可以通过JS+PHP实现,也可以通过PHP + MYSQL+JS实现,只不过JS+PHP比较方便而且效率更高罢了. 下面是PHP + MYSQL+JS实现办法. 每次显示10条数据. 1 public function get_data($limit){ 2 $sql="select * from