Load can only be called when the EntityCollection or EntityReference does not contain objects

江枫思渺然 提交于 2021-01-27 08:17:14

问题


As Title showed, When I use lazyload of Entity Framework 4.1 which turned tracking off I got the error.

Complete exception message:

When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects

Does anyone knows why?


回答1:


Set the Configuration.ProxyCreationEnabled field of your DbContext to false:

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

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



回答2:


I also have the same problem. Apparently it is a bug in EF 4.1 Bug ticket



来源:https://stackoverflow.com/questions/8292149/load-can-only-be-called-when-the-entitycollection-or-entityreference-does-not-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!