My scenario is below:
I am using EF4 and use linq.
I have a datagrid which is bound to a ICollectionView (bacause I use filtering) as below:
view = CollectionViewSource.GetDefaultView(lstOrdsRlsd);
if (lstOrdsRlsd.Count > 0)
{
dgRecords1.ItemsSource = view;
}
where lstOrdsRlsd is an observablecollection.
My problem is :
I need to refresh the datagrid when something is changed in the database (whether its adding a new row or changing some property of one record etc).
I tried datagrid.Items.Refresh() which didnt work.
Can I use INotifyPropertyChanged in this case? Could someone give some sample code about how to implement this?
Thanks
You can try using the DbSet<>.Local property. This is an observable collection with all the rows that you have queries from you database context.
So if you do any queries later, and more rows comes back, the DbSet<>.Local collection will INotifyCollectionChanged for you. 🙂
So the next step is to then make sure EF fetches the new rows. You could use anything from Daniel Hilgarth’s answer to implement that.