WPF Reflections

Feb 19 2008   4:08PM GMT

WPF databinding to Linq



Posted by: Mark Shurmer
WPF

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:

  1. Use a framework like CSLA (and I’m going to look a lot more closely at the v3 of CSLA which supports WPF)
  2. 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?
  3. Bind the control to the EntitySet’s GetNewBindingList(), which will dynamically update the control for you
  4. 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

Comment on this Post


You must be logged-in to post a comment. Log-in/Register