惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
小众软件
小众软件
F
Fortinet All Blogs
博客园 - 叶小钗
博客园_首页
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
U
Unit 42
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
IT之家
IT之家
M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog

博客园 - Xia.CJ

C# 委托 node.js中连接mongodb(Please ensure that you set the default write...)解决办法 node.js api解读之file system模块 Node.js小技巧 在windows上安装新版node.js-node.js学习笔记 Asp.Net MVC部暑托管服务器iis7提示403错误解决方法 mvc3中使用unobtrusive时,ajax更新加载页面后验证失效解决方法 ashx中使用HttpContext.Current.Session ,出现未将对象引用设置到实例上 搜索引擎(google/百度)高级指令 在mvc3中使用uploadify上传组件User.isAuthenticated等于false解决方法 MVC中用Html.RenderPartial还是Html.RenderAction或者Html.Partial-Xia.CJ 在_Layout使用Html.RenderAction的问题-MVC3(Razor)问题 无法删除此对象,因为未在 ObjectStateManager 中找到它-entity framework删除时 Javascript数组(array)操作 entity framework(EF)_code first复杂类型(Complex Types)问题 entity framework多对多关系查询 JQuery获取checkbox值,checkbox全选,操作checkbox JQuery操作Select JQuery动态创建DOM、表单
序列化类型 System.Data.Entity.DynamicProxies 的对象时检测...
Xia.CJ · 2012-03-31 · via 博客园 - Xia.CJ

序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用

entity famework+asp.net mvc 做code first项目的时候,前台ajax请求到后台 JsonResult

在后台返回  return Json(list, JsonRequestBehavior.AllowGet)的时候,出错:

序列化类型 System.Data.Entity.DynamicProxies 的对象时检测到循环引用。

解决方法:

  1.可以在查询的时候这样子

var list = from f in db.Categories
//这里要select new
select new
{
Id = f.Id,
Name = f.Name,

};

2.你可以尝试删除所有导航属性virtual关键字禁用延迟加载创建代理,然后使用预先加载,而不是显式地加载所需的对象图

public ActionResult GetAll()
{
return Json(Context.Categories
.Include(o => o.Products)
,
JsonRequestBehavior.AllowGet);
}

看起来像是依赖于延迟加载无论如何,因为你使用virtual属性延迟加载对象图,可能会造成现在的系列化的麻烦
3.没有必要删除virtual关键字导航性能(这将使延迟加载模型完全不可能这足以创建代理以及禁用延迟加载禁用代理扰乱序列一样具体情况

Context.Configuration.ProxyCreationEnabled = false;

这将禁用仅适用于特定上下文实例Context创建代理