WPF Reflections

Feb 24 2008   10:11PM GMT

Databinding with Linq with automatic updates

Mark Shurmer Profile: MarkWPF

How do you databind to an EntitySet retreived from a Linq query, via Linq to Sql or Linq to Entities for example?

Well it is very easy to actually bind to it, you simply connect it up using normal Xaml syntax. But what if you want to have updates automatically relected in the UI? That’s something that ObservableCollection does very well, due to it’s implementation of INotifyCollectionChanged. So why didn’t they implement INotifyCollectionChanged in the EntitySet class? Who knows? It would have saved me a load of grief, for starters.

For a list of your different options, see a previous post of mine.

Here I will show how I have got around the problem:

I have a database table called Profiles, which using the Linq for Sql visual designer gives me a class called ProfilePart. As it is a partial class I can have another cs file with my ProfilePart definition and provide my binding implementation.
How do I it? I call the GetNewBindingList() method on the EntitySet, but I need to cache it as I don’t want to do it every time it is accessed.

An example is shown below:


1  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.
  • Mrbiancardi
    it is possible to see an example with ObservableCollection. I use Microsoft Blend and I would want to implement Linq. Please help me.
    0 pointsBadges:

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: