Skip to main content

Microsoft Silverlight

Unanswered Question ObservableCollection-over-WCF-to-Silverlight 3-and-backRSS Feed

(0)

NWA210
NWA210

Member

Member

8 points

15 Posts

ObservableCollection-over-WCF-to-Silverlight 3-and-back

I'm wondering if you can explain an ObservableCollection-over-WCF-to-Silverlight 3 question. I've been trolling the Internet for days and I'm running out of time to figure this out.

Suppose you have an ObservableCollection of POCOs that inherit from INotifyPropertyChanged like this guy has http://weblogs.asp.net/joelvarty/archive/2008/11/17/silverlight-databinding-the-observable-collection.aspx

Now suppose you return his UserCollection to a Silverlight client over WCF and the client puts the collection in a DataGrid.ItemSource. Now someone modifies a name in one of the FirstName cells of the grid.

How do you get just that changed cell or row of that cell to go back to the middle tier? Or if you send the whole UserCollection back to the middle tier how can you tell what's changed in the collection?

In my case since I cannot figure out how to send just the changed rows back the middle tier, I created an [OperationContract] method in my WCF service which takes the whole collection:

  SaveChanges(ObservableCollection<Person> person)

and in my Silverlight client I have a button click event call the method

  svc.SaveChanges(datagrid.ItemSource)

When the WCF method receives the collection, I can see the modified name if I inspect each row however I have no idea how to programmatically know that the name has been modified in any given row. - the same problem I had in the Silverlight client, of course. Where does INotifyPropertyChanged fit into this scenario?

Ultimately, I need to transfer the changed information from the POCOs to EntityFramework objects so that the change makes it back to the database.

mrjvdveen
mrjvdveen

Participant

Participant

1939 points

367 Posts

Re: ObservableCollection-over-WCF-to-Silverlight 3-and-back

 You'd have to record the changes as they happen, indeed by using INotifyPropertyChanged. You could record the changes in a seperate instance of the same class and compare each property, or you could write a simple class that has an Id and a set of changes, consisting of a fieldname and it's new value. Send that instance to the service and you know what to update.

I know it's a hassle and it's exactly the reason why our team don't use POCOs. We use a set of base classes that handles all this stuff for us, including a large part of the save.

HTH.

-------------
Please mark a post as answer if it answers your question.
Visit my blog: http://jvdveen.blogspot.com

NWA210
NWA210

Member

Member

8 points

15 Posts

Re: ObservableCollection-over-WCF-to-Silverlight 3-and-back

I'm not sure how to subscribe to the PropertyChanged event in my Silverlight code.

mrjvdveen
mrjvdveen

Participant

Participant

1939 points

367 Posts

Re: ObservableCollection-over-WCF-to-Silverlight 3-and-back

 You'd have to take each instance and attach to the event like this:

myPoco.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(myPoco_PropertyChanged);

 HTH.

-------------
Please mark a post as answer if it answers your question.
Visit my blog: http://jvdveen.blogspot.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities