error on Cancel Changes

May 13, 2010 at 3:05 PM

I have app running and added one category record.

Edited long description and clicked Save - db got updated.

Made another edit in long description field and clicked Cancel - got error "Load operation cannot be performed when CanLoad is false"

Coordinator
May 13, 2010 at 3:21 PM

Which version of VS/Silverlight Tools/RIA Services are you using? This code was written against the beta, migrated to RC...haven't fully tested under RTM of VS or the latest silverlight tools.

May 13, 2010 at 3:47 PM

I'm running VS2010 RTM w/WCF RIA Services V1.0 for VS2010 and Silverlight V4.

What I found was that the CategoryDomainDataSource.HasChanges = true which causes CanLoad to be false.

Changed the code to:

    private void CancelButtonClick(object sender, RoutedEventArgs e)
    {
      if (CategoryDomainDataSource.HasChanges)
      {
        CategoryDomainDataSource.RejectChanges();
      }
      CategoryDomainDataSource.Load();
    }

Now it works.   Is there a better way to handle this?  thanks!

Coordinator
May 13, 2010 at 9:29 PM

Thanks for the solution tkraft...one of the goals of the article is to show how to remove those concerns from your UI. Even in the simpler scenarios, we can see the benefit of leveraging some of these patterns to do our dirtywork. For instance, removing the DomainDataSource altogether and using a ViewModel to abstract the details away will allow us to work in a more natural manner. True, we loose some of the benefits of DDS, but it also allows our code to be blissfully unaware of those concepts.

Coordinator
May 13, 2010 at 9:32 PM

There is a happy in between as well. The Viewmodel could be responsible for interacting with the DDS (in terms of committing/cancelling changes). I'll show how this works in the next checkin.

May 13, 2010 at 9:35 PM

Great, looking forward to it.

Toby

Coordinator
May 15, 2010 at 1:05 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.