在序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。 [英] A circular reference was detected while serializing an object of type 'SubSonic.Schema .DatabaseColumn'.

查看:228
本文介绍了在序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public JsonResult GetEventData ()
{
var data = Event.Find(x => x.ID!= 0);
return Json(data);
}

我收到一个HTTP 500,例外情况如此题目所示。我也试过

  var data = Event.All()。ToList()

同样的问题。



这是一个错误还是我的实现? >

解决方案

似乎在对象层次结构中有一些循环引用,它不受JSON序列化程序的支持。你需要所有的列吗?您可以在视图中只接收您需要的属性:

  return Json(new 
{
PropertyINeed1 = data.PropertyINeed1,
PropertyINeed2 = data.PropertyINeed2
});

这将使您的JSON对象更轻更易于理解。如果您有许多属性,则 AutoMapper 可用于映射DTO对象和View对象之间的.com / blogs / jimmy_bogard / archive / 2009/06/29 / how-we-do-mvc-view-models.aspx。 p>

I am trying to do a simple JSON return but I am having issues I have the following below.

public JsonResult GetEventData()
{
    var data = Event.Find(x => x.ID != 0);
    return Json(data);
}

I get a HTTP 500 with the exception as shown in the title of this question. I also tried

var data = Event.All().ToList()

That gave the same problem.

Is this a bug or my implementation?

解决方案

It seems that there are circular references in your object hierarchy which is not supported by the JSON serializer. Do you need all the columns? You could pick up only the properties you need in the view:

return Json(new 
{  
    PropertyINeed1 = data.PropertyINeed1,
    PropertyINeed2 = data.PropertyINeed2
});

This will make your JSON object lighter and easier to understand. If you have many properties, AutoMapper could be used to automatically map between DTO objects and View objects.

这篇关于在序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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