仅当EntityCollection或EntityReference不包含对象时,才可以调用加载 [英] Load can only be called when the EntityCollection or EntityReference does not contain objects
本文介绍了仅当EntityCollection或EntityReference不包含对象时,才可以调用加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如Title所示,当我使用Entity Framework 4.1的lazyload(关闭了跟踪)时,出现了错误.
As Title showed, When I use lazyload of Entity Framework 4.1 which turned tracking off I got the error.
完整的异常消息:
使用NoTracking合并选项返回对象时,只能在EntityCollection或EntityReference不包含对象的情况下调用Load
When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects
有人知道为什么吗?
推荐答案
将 DbContext
的 Configuration.ProxyCreationEnabled
字段设置为 false
:
using (var dbContext = MyDbContext())
{
dbContext.Configuration.ProxyCreationEnabled = false;
return dbContext.MyProducts.AsNoTracking().Where(product => product.DepartmentId = departmentId);
}
这篇关于仅当EntityCollection或EntityReference不包含对象时,才可以调用加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文