【问题标题】:Load can only be called when the EntityCollection or EntityReference does not contain objectsLoad 只能在 EntityCollection 或 EntityReference 不包含对象时调用
【发布时间】:2015-12-17 04:01:58
【问题描述】:

正如标题所示,当我使用 Entity Framework 4.1 的延迟加载关闭跟踪时,我得到了错误。

完整的异常信息:

当使用 NoTracking 合并选项返回对象时,只有在 EntityCollection 或 EntityReference 不包含对象时才能调用 Load

有人知道为什么吗?

【问题讨论】:

  • 你能在哪里发布代码吗?

标签: entity-framework


【解决方案1】:

DbContextConfiguration.ProxyCreationEnabled 字段设置为false

using (var dbContext = MyDbContext())
{
    dbContext.Configuration.ProxyCreationEnabled = false;

    return dbContext.MyProducts.AsNoTracking().Where(product => product.DepartmentId = departmentId);
}

【讨论】:

    【解决方案2】:

    我也有同样的问题。显然这是 EF 4.1 中的一个错误 Bug ticket

    【讨论】:

    • 现在我必须添加一个相关属性以确保实体将被代理
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 2016-01-09
    • 2021-10-21
    • 2018-07-21
    • 1970-01-01
    相关资源
    最近更新 更多