Do I need to implement INotifyPropertyChanged when using EF Code-First?

I notice that when using EF CodeFirst and binding my user interface to ObservableCollection<T>using the DBSet.Localrecommended property here is that the user interface will be updated when entities are added to the DBC text, but not when they are changed.

It would seem that the collection DBSet.Localwould not be notified that my entities have changed. When using EF Code-First do I need to implement INotifyPropertyChangedfor all my fields? I have not seen this in any of the Code-First examples, and it seems to be against the goal, but maybe I'm wrong.

I can post some sample code if you feel like you ObservableCollectionshould be notified of changes and that something should be wrong in my Entity classes or something like that.

Change . Therefore, to be sure that in my ViewModel

there is a code like the one below:
private ClientContext clientContext;
private Client client;
public Client Client
{
    get { return client; }
    set { 
          client = value; 
          NotifyOfPropertyChange(() => Client);
          NotifyOfPropertyChange(() => Clients);
        }
}
public ObservableCollection<Client> Clients { get { return clientContext.Clients.Local; }}

Suppose also that my view has a Listbox with an Itemssource set to Clients and a SelectedItem for a client. Do I still need to implement INotifyPropertyChanged in my model, even if I use it in my ViewModel?

+1
source share
2 answers

Yes,

Each element that you want to update when its property is modified must implement INotifyPropertyChange.

, , , , CollectionChanged,

: CTP5 Framework Entity Framework WPF-MVVM-

+3

, , .

, "", INotifyPropertyChanged , ( , ).

, TextBox .

! , TextBox Text SelectedItem DataGrid ( ObservableCollection .Local) UpdateSourceTrigger = PropertyChanged. DataGrid TextBox, DataGrid ! , DataGrid!?!?!

:

<TextBox Text="{Binding Path=SelectedItem.Name, UpdateSourceTrigger=PropertyChanged}" />

TextBox , SelectedItem , TextBox, . ( DataGrid !)

! SelectedItem.Name = " ", , , DataGrid. ( DataGrid , MVVM )

. EF4.1 DBContext POCO (.. , )

0

All Articles