Thursday, March 31, 2011

DomainDataSource and Composites, problem with HasChanges

There is a subtle bug in current version of WCF RIA (v1 sp1) related to using composites client-side. Sometimes when you change not only you CompositionRoot object but also one of its children and then submit that changes, you may notice that change tracking started behave strangely i.e. any further modifications of any part of composite will change entity’s HasChanges and DomainContext’s HasChanges to true, but associated DomainDataSource will remain with “no changes” (HasChanges == false). To fix that you need to do two things

  1. Subscribe on SubmittedChanges of your DomainDataSource
  2. AcceptChanges for your entire EntityContainer inside event handler

or speaking C#

YourDomainDataSource.SubmittedChanges += SubmittedChanges;
// workaround to prevent stale HasChanges on DDS
private void SubmittedChanges(object sender, SubmittedChangesEventArgs e)
    if (!e.HasError)

1 comment:

  1. Hi Sergey,

    I use composition and do accept changes using IChangeTracking as well as reject changes using IRevertableChangeTracking on my domain context, despite the fact that the domain context is in the proper state, the associated domain data source still shows HasChanges = true (and CanLoad = false).
    What else can I try to reset my DDS so that I can load again?