I'm migrating my EF6 MVC project from ObjectContext to DbContext with lazy loading.
With ObjectContext, I could do the following:
// Create a new user:
User u = new User();
u.LineManagerID = 42; // Set foreign key
db.Users.Add(u);
db.SaveChanges();
// get property of related entity as set above by foreign key
User lm = u.LineManager;
With DbContext, u.LineManager
is null even the the new entity is saved correctly and I suspect if I did another call to the database it would be fine.
Lazy loading and dynamic proxies are both enabled.
Why doesn't the new entity refresh properly?
Please help! I can see this migration is going to be lot harder than I thought...!
EDIT - I should add that I am using db-first code generation