This question has already been answered:

Faced with this situation. The program is running. I am changing the data in the wrk_Device_Value table NOT from the program. Next, I run a method to populate the collection, which contains the string below. The query to the database is executed (I look through Profiler), while the data in the collection remain the same.

What could be the error?

ValuesList = new ObservableCollection<wrk_Device_Value> (_dataContext.wrk_Device_Value.Where(d => d.ID_Device == device.ID_Device).ToList()); 

Reported as a duplicate by the participants of VladD , LEQADA , Nick Volynkin Jan 29 '16 at 5:15 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • "I am changing the data in the wrk_Device_Value table NOT from the program" - do you save the changes? - Stack
  • @Stack, yes, the request read by the profiler is checking for new data, but the collection is not updated - Alex
  • In the framework of the EF session, most likely the data is obtained once, then the work is done with the cache. If you need to receive data from the table explicitly every time - open a new session for each other. From EF did not work, I estimate on the situation. - Monk
  • Hmm .. And what's the update strategy? - Qwertiy
  • @Qwertiy I'm still new to this. What is meant? If that's how I change the data in the table, then just through SQL Man. Studio change the value in the table. - Alex

1 answer 1

When recreating a collection, you must manually call RaisePropertyChanged("ValuesList") , or declare a ValuesList like so:

 private ObservableCollection<wrk_Device_Value> _valuesList; public ObservableCollection<wrk_Device_Value> ValuesList { get { return _valuesList; } set { if (_valuesList == value) return; _valuesList = value; RaisePropertyChanged("ValuesList"); } } 
  • Did not help. The data is still old - Alex
  • _dataContext.wrk_Device_Value.Where(d => d.ID_Device == device.ID_Device).ToList() code _dataContext.wrk_Device_Value.Where(d => d.ID_Device == device.ID_Device).ToList() in a separate variable and look at the contents in debug mode, whether the wrong data or the problem with the display comes. - Anton Papin
  • Checked Old data is written to the variable and loaded when the program is started. - Alex
  • The problem seems to be with the model class. If I change the value of one field in a table through MSSQL and update the collection, the data in the collection remains the same. And when you delete a row in the table, the data in the collection is updated. What can be wrong? - Alex
  • You really should look towards caching. Somewhere it happens with you, and where, without knowing the project, it is quite difficult to predict. - Anton Papin