4
votes

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?

2
Can you post code where exactly this was raised?Akash Kava

2 Answers

3
votes

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);
}
0
votes

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