Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello everyone,

I have a small program (multi user).

When I run 2 sessions of my program and in session 1 I do an update of the data, I can't see the updated data in session 2. However the updated data is stored correctly in the database.

When I do an insert in session 1, I see the insert in session 2.

My plan was to do a refresh of the context, but this doesn't seems to be possible.

Has anyone the same problem and a simple solution?

Many thanks in advance!
Posted

You could refresh only the needed data set by using:
this.MyObjectContext.Refresh(RefreshMode.StoreWins, this.MyObjectContext.MyObjectSet);<br />

But I recommend to use the advises from Solution1 and to use the method above only when you realy need it!
 
Share this answer
 
v2
Comments
aanbidmij 1-Jun-14 4:17am    
In my program I use the class Context not ObjectContext... apperantly in the class Context the method .Refresh(...,...) doesn't exist
If you're creating an instance of the context and keeping it alive for the lifetime of the application, you're doing it wrong.

Create a context when you need to do a query and Dispose it when you're done. This way, you don't have to "refresh" it. It'll pickup the new data when ever you do your next query for it.
 
Share this answer
 
Comments
aanbidmij 31-May-14 10:32am    
That was what i tought at first. I have changed my code I use a generic repository and have declared my context like this => static Context cts = new Context(); but i still have the same problem
you can use Refresh method of the context or dispose the old context and create again. But if you need to refresh only when the context change and it need to be happen automatically whenever database changed. Then you can try below article with SQL Server Service Broker.
AutoRefresh Entity Framework Data Using SQL Server Service Broker[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900