Generally, the context.Refresh is intended to refresh an object that gave you an OptimisticVerificationException
as described in this documentation article
. You should have in mind though that calling the Refresh method will result in multiple database calls - at least one query per item that needs to be refreshed. So using it with large collection of objects will most likely lead to performance issues.
Could you please give us a bit more information on your implementation scenario so we could advice you better? Is your goal to decide on the life-cycle of a context - whether to use a long living or a short living context? Do you have a web application or a desktop one?
Generally speaking out recommendation is to use short living context nevertheless this is a design decision you have make based on you implementation scenario and requirements. Short living contexts does not hold opened connections, they allow better transaction management as less operations will be executed from the same instance. Short living context are the recommended approach in multi threaded scenarios - this would prevent one thread pushing changes that are mode by another thread.
On the other hand, a long living context has a richer level one cache (this could also be a reason for higher memory consumption).
I hope this is helpful. Do not hesitate to contact us back with any further questions.
Check out the latest announcement
about Telerik Data Access vNext as a powerful framework
able to solve core development problems.