Domain Data Source CanLoad is false when using RIA Query Parameter bound to a dependency property

2.7k Views Asked by At

I have a ria DDS query whose parameter is bound to a dependency property of the code behind my silverlight page. The issue is that once the project dependency is changed I get the following error.

QueryParameters cannot be changed when CanLoad is false. Changing the QueryParameters initiates a load operation, and load operations are not permitted when CanLoad is false. Controls that invoke load operations should be disabled when CanLoad is false.

I'm at a loss on how to complete or cancel the load so I can change the details view for a project every time a new project is selected from a list.

<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:XT_PROJECTS, CreateList=true}" Height="0" LoadedData="ProjectDetailsDomainDataSource_LoadedData" Name="ProjectDetailsDomainDataSource" QueryName="getProjectDetails"  Width="0" >
        <riaControls:DomainDataSource.DomainContext>
            <my:MYservices />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.QueryParameters>
            <riaControls:Parameter ParameterName="project" Value="{Binding ElementName=ProjectDetailsPage, Path=project}" />
        </riaControls:DomainDataSource.QueryParameters>
    </riaControls:DomainDataSource>

public static readonly DependencyProperty projectIDDP =
    DependencyProperty.Register("project", typeof(string),typeof(ProjectDetails),
    new PropertyMetadata(""));
 public string projectID
    {
        get
        {
            return (string)GetValue(projectIDDP);
        }
        set
        {
            SetValue(projectIDDP, value);
        }
    }
2

There are 2 best solutions below

2
On

Does this work adding a submit before changing the parameter? like this

set
{ 
    if (xyzDomainDataSource.HasChanges)
        xyzDomainDataSource.SubmitChanges();
    SetValue(projectIDDP, value);        
}
1
On

After a bit more research I'm now pretty sure you must have pending changes in you context. In that case, DomainDataSources "block" and you must not cause a load for them.

If this error occurs in a different scenario, I'd be very interested to be corrected on this.

If you have pending changes, your solution is either

  1. to block user input (presumably the ultimate cause of your load), for example by disabling the form or
  2. to use a different context for the submission and the DomainDataSource (you will then want to use RiaServicesContrib to do copying of entities between contexts).