I recently discovered the hard way that EF does caching. I have a root viewmodel that creates the initial DbContext
. With every other viewmodel that gets created, I pass that context over. That way, I only have one connection, and I have dependency injection.
I have a function in one of the viewmodels that changes a state one of the entities. When I get attempt to get the entity back from the database, the status remains unchanged (I'm assuming this is due to caching).
All the other posts I've found (that's for EF 6), wants to create a NEW instance of the class, like this :
var context = new MyContext();
Which would work, but it would prevent me from having only one connection, and also eliminate my dependency injection.
Is there any other way of getting the true value of the entity?