亚音速3.0.0.2 Structs.tt(SubSonic 3.0.0.2 Structs.tt)

2019-09-21 04:24发布

我得到的错误似乎走出Structs.tt文件。 我使用的是罗斯文数据库,并只使用产品表(我排除了所有其他表)。 我返回JSON(Product.All())。

这里的错误:

而序列化类型SubSonic.Schema.DatabaseColumn'.Here的所述堆栈跟踪的”对象时检测到循环引用:

System.InvalidOperationException了由用户代码消息=未处理的“在序列化类型‘SubSonic.Schema.DatabaseColumn’的对象的循环引用检测”。 源= “System.Web.Extensions程序” 堆栈跟踪:在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer。 SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,serializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,serializationFormat serializationFormat)在System.Web程序。 Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,serializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,serializationFormat serializationFormat )在System.Web.Script.Serialization.JavaScriptSeri alizer.SerializeCustomObject(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在系统。 Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,serializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable的枚举,StringBuilder的SB,深度Int,哈希表objectsInUse, SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表 objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer。 SerializeEnumerable(IEnumerable的枚举,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web程序。离谱 pt.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat )在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(对象O,StringBuilder的SB,深度Int,哈希表objectsInUse,SerializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(对象O,StringBuilder的SB,深度Int ,哈希表objectsInUse,serializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(对象OBJ,StringBuilder的输出,serializationFormat serializationFormat)在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(对象OBJ,serializationFormat serializationFormat)在系统.Web.Script.Serialization。 JavaScriptSerializer.Serialize(对象OBJ)在System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext上下文)在System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,的ActionResult的ActionResult)在System.Web.Mvc.ControllerActionInvoker。<> c__DisplayClass11 .b__e()在System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter滤波器,ResultExecutingContext preContext,FUNC1续)在System.Web.Mvc.ControllerActionInvoker。<> c__DisplayClass11。<> c__DisplayClass13.b__10()在System.Web.Mvc .ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,IList1过滤器,的ActionResult的ActionResult)在System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,字符串actionName)在System.Web.Mvc.Controller.ExecuteCore()在System.Web.Mvc。 ControllerBase.Execute(RequestContext的的RequestContext)在System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContex 吨的RequestContext)在System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase HttpContext的)在System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext的HttpContext的)在System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext的HttpContext的)在System.Web.Mvc.MvcHttpHandler.VerifyAndProcessRequest(的IHttpHandler HttpHandler的,HttpContextBase HttpContext的)在System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase HttpContext的)在System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext的HttpContext的)在的System.Web .Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext的上下文)在ExtJSNorthwind._Default.Page_Load(对象发件人,EventArgs e)如C:\应用程序\尖峰\ ExtJSNorthwind \ ExtJSNorthwind \ Default.aspx.cs:线18在错误帮助(IntPtr的FP,对象O,对象吨,EventArgs e)上System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发件人,EventArgs e)上System.Web.UI.Control.OnLoad( EventArgs的 e)上System.Web.UI.Control.LoadRecursive()在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)的InnerException:

Answer 1:

看来我们有一个问题与序列化:)。 能否请您将其添加为我们的名单上的问题吗? 我会很感激。



Answer 2:

这是很容易解决。 您需要只需添加一个ScriptIgnore属性的一对夫妇在ActiveRecord.tt文件的方法。 下面是我所做的更改。

        [ScriptIgnore]
    public IList<IColumn> Columns{
        get{
            return tbl.Columns;
        }
    }

注:我还加了属性下面的方法,虽然如果需要在你的情况我不知道

        [ScriptIgnore]
    public IQueryable<<#=fk.OtherClass #>> <#=propName #>
    {
        get
        {

              var repo=<#=Namespace #>.<#=fk.OtherClass#>.GetRepo();
              return from items in repo.GetAll()
                   where items.<#=CleanUp(fk.OtherColumn)#> == _<#=CleanUp(fk.ThisColumn)#>
                   select items;
        }
    }


文章来源: SubSonic 3.0.0.2 Structs.tt