问题
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