简体   繁体   中英

WPF Entity Framework binding to navigation property not updating

I have a viewmodel with a Customer property bound to an Entity Framework object. The customer object has multiple navigation properties to other tables. My view displays properly if there is already an existing record in one of the dependent tables and I can edit and save, but when I try to add a new object to the Customer property like:

Customer.BillingDetail = new CustomerBillingDetail();

The view will not bind to the new object even though the viewmodel Customer property is populated with a blank object. So when I go to save, none of the entered values are persisted to the viewmodel, it still has the blank object.

So, how do I get the view and viewmodel to communicate on the addition of a new object to the navigation property?

Is there something I'm missing in the viewmodel for tracking the property change of the Customer navigation properties?

Thanks, -Sid.

我猜你的EF对象没有实现INotifyChanged并且不使用ObservableCollections

Just clear me one one thing, when you bind the view with the values in customer object and make some changes in any of the binded control. Does that change persist in the database. If not then You must try to bind the property with TwoWay mode.

It helps to update your customer object from the binded control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM