Reputation: 777
Hello guys I have the following method:
var usuario;
usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario == VWUsuarioUniaponta.IdUsuario &&
x.PlanejamentoEstrategico.IdPlanejamentoEstrategico == HorarioTrabalhoCorrente.PlanejamentoEstrategico.IdPlanejamentoEstrategico);
TxtTotalHorasMes.Text = usuario.QuantidadeHorasDisponivelMes.ToString();
usuario = null;
When executes this method, and then executes it again it seem that the EF or something is caching the value of the first query: Exemple: go though the method, query for usuario that is 25, in that then i set null (that was a test) later on in the execution even changing that value in database, when it passes in this method again the variable is still 25....and when I save changes in another method it tries to save usuario from another method. This seems wrong because the variable scope is local and not global The Problem is, when the method is over it should not destroy that variable? How I can solve this??
Upvotes: 1
Views: 567
Reputation: 110171
EF's ObjectContext tracks the objects that it loads. If you ask for the objects again, it gives you the same instance (not a copy) it gave you before.
http://msdn.microsoft.com/en-us/library/bb896269.aspx
The ObjectContext instance IS the scope of these instances. If you want to start a new UnitOfWork, you should start with a new ObjectContext.
Upvotes: 2