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

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

问题描述

我试图做一个简单的JSON回报,但我有问题,我有以下以下。

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);
}

我得到一个HTTP 500除了如图这个问题的称号。我也试过

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?

推荐答案

这似乎也有不支持的JSON序列中的对象层次循环引用。你需要的所有列?你可以拿起只需要在视图属性:

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
});

这会使你的JSON对象更轻,更容易理解。如果你有很多属性, AutoMapper 可用于<一个href="http://www.lostechies.com/blogs/jimmy%5Fbogard/archive/2009/06/29/how-we-do-mvc-view-models.aspx">automatically DTO对象和视图对象之间的映射。

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天全站免登陆