开发者

Entity Framework - Code First, DbSet.Local Not Updating in UI

I have a Code First, CTP5 data context. I have a WPF app with a DataGrid. I set its DataContext like:

dataGrid.DataContext = _context.Customers.Local;

then I add a few entities using

_context.Customers.Add(customer1); and so on
_context.SaveChanges();

Then, I give these customers (a 开发者_C百科list of the customers) to another class to do some work on them.

customerUpdater.Update(customers);

That takes a long time and it updates properties of each customer while it's working. e.g.

foreach(var customer in customers) { customer.Name = "updated name"; }

I'm not seeing those updates in my WPF UI though! All I see are the original list of unaltered customers. Customers.Local is an ObservableCollection though, so I don't understand why I'm not seeing the updates in the UI.

I don't want to call SaveChanges() every time a property update occurs, it would be nearly constantly. Can someone tell me why this won't update?


If Customers.Local is an observableCollection, and you update the property "name" of one of their items, you are not seeing the updates because you are not modifying the observable collection, what you are modifying is the value of a property of one of the items (customer) present in the observableCollection, but the observableCollection will not send any notifications to the UI because it remains unchanged (it has the same number of items)

If you want the UI to be notified when you update the property name of a customer, you have to make the customer class to implement the INotifyPropertyChanged interface.

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜