【问题标题】:unhandled exception of type 'System.AccessViolationException' occurred while using 2 include in a EF query在 EF 查询中使用 2 包含时发生“System.AccessViolationException”类型的未处理异常
【发布时间】:2018-06-14 06:06:40
【问题描述】:

我将第二个 Include 添加到我的 EF 查询中

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

我得到了这个错误:

“System.AccessViolationException”类型的未处理异常 发生在未知模块中。试图读或写保护 记忆。这通常表明其他内存已损坏。

有人知道我为什么会出现这个错误吗?

【问题讨论】:

  • 欢迎来到stackoverflow;请提供minimal reproducible example
  • 当我使用2“包含”时出现此错误。只有一个,它工作正常,但我需要加载两个相关实体(“tblAnimalSubCategorie”和“tblStal”)
  • 信息不足。什么版本的实体框架?什么数据库提供商等?
  • 我使用的是EF6和sql server

标签: c# entity-framework include


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2016-01-07
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多