WPF Reflections

Feb 19 2008   4:08PM GMT

WPF databinding to Linq

Mark Shurmer Profile: 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:

  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

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: