Posted by: MarkWPF
I think I have (at last) the workaround that gets WPF to bind to objects from Linq (to SQL or Entities or anything…)
The problem is that Linq’s EntitySet class doesn’t implement INotifyCollectionChanged, so when you bind to an object that contains child collection classes you don’t get automatic notification of changes to your collection.
You basically have four choices:
- Use a framework like CSLA (and I’m going to look a lot more closely at the v3 of CSLA which supports WPF)
- Create another class (and all child classes) and copy data out of the EntitySet into the new class and put that in an ObservableCollection. Then when you save copy it back into a new Linq DataContext (and all the child classes) – do you think yuk like me?
- Bind the control to the EntitySet’s GetNewBindingList(), which will dynamically update the control for you
- Create a BindingSource object and set it’s DataSource to the EntitySet’s GetNewBindingList() call and then bind the control to the BindingSource
Which you choose depends on the circumstances though of course