在EF查询中使用2 include时发生未处理的类型'System.AccessViolationException'的异常

问题描述 投票:-3回答:1

我在我的EF查询中添加了第二个Include

return entities.lnkAnimalSubCategories.Where(t => t.tblVersie.Naam.Equals(webVersie)).Include("tblAnimalSubCategorie").Include("tblStal").ToList();

我收到了这个错误:

未知模块中出现未处理的“System.AccessViolationException”类型异常。试图读取或写入受保护的内存。这通常表明其他内存已损坏。

有谁知道为什么我有这个错误?

c# entity-framework include
1个回答
-1
投票

问题是:Json无法处理循环对象引用。为了解决这个问题,我在Global.asax中添加了以下代码

var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Array;

© www.soinside.com 2019 - 2024. All rights reserved.