Search code examples
c#wpfentity-frameworkobservablecollectionicollection

Is it smart to replace ICollection with ObservableCollection<T> wpf ef


I'm a beginner with wpf app building and entity framework.
I'm building my first wpf app, I found out I should have replaced my auto-generated ICollection with ObservableCollection.
The problem is that I already did most of my code so far but am having some issues with INotifyPropertyChanged. I see all the codes about INotifyPropertyChanged use ObservableCollection.

Is it bad if I go to my auto-generated code now and replace the ICollection with ObservableCollection? Will it mess up my app?


Solution

  • ObservableCollection is only useful if you want to add items to a collection at some point, and have a UI control automatically update to display the added / deleted items. ObservableCollection also has potential threading issues - any change to the collection must be done on the same thread as it was created on.

    It has nothing to do with reflecting changes to properties of individual elements within the collection - that is what INotifyPropertyChanged is for.