1

When i run 2 instances of my application in front of a comon SQL SERVER DB i have the following behavior: each time an object is added or removed, the other app sees it each time an update is done to the object, the other does not see it until i close and open the application

I'm working with WPF bindings and EF4 Any clue ? thanks Joghn

user96547
  • 573
  • 10
  • 18

2 Answers2

0

Your app is maintaining state, that is a copy of the data, in memory.

When you change the data in one instance of the app and save the data to the database, it has no effect on the memory in the second instance of the app.

For it to show up in the second instance you must get the data from database.

What I think you are doing is a refresh on the data. What EF does is it says "I have these 5 rows are there any chages to this data on the server". It is only refreshing rows that have been retrieved previously.

You need to use the code that you use to load the data on application start. You must also be carefull if you are reusing the dbContext.

Shiraz Bhaiji
  • 60,773
  • 31
  • 133
  • 239
0

I think you are reusing context, don't you? EF will not load changes automatically. If you run the query, then modify data in the database and then run the same query again you will get the same result as in the first query, only new records will be added. That is how EF behaves and this behavior is very important in ORM tools. If you want to force context to reload data and throw away the state you have in the application (= all unsaved changes will be lost) you must run the query with MergeOption.OverwriteChanges (example here) or call Refresh method with RefreshMode.StoreWins.

Community
  • 1
  • 1
Ladislav Mrnka
  • 349,807
  • 56
  • 643
  • 654