This is a migrated thread and some comments may be shown as answers.

Change Query to Query+QueryParameters and back

2 Answers 172 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Nikita
Top achievements
Rank 1
Nikita asked on 27 Jan 2011, 01:55 AM
Hi!
There is the RadDDS and the RadGridView in the xaml:
<telerik:RadDomainDataSource
    x:Name="RadSource"
    DomainContext="{Binding Path=context}"
    QueryName="GetPersonSetQuery"
    AutoLoad="True" />
<telerik:RadGridView
    x:Name="RadGV"
    ItemsSource="{Binding ElementName=RadSource, Path=DataView}"
    AutoGenerateColumns="True"/>

I need to change the query to query+parameters in my code-behind. I do it this way:
using swd = System.Windows.Data;
using twc = Telerik.Windows.Controls;
 
RadSource.AutoLoad = false;
RadSource.DomainContext = null;
RadSource.QueryName = "GetPersonSetByDepartmentId";
RadSource.QueryParameters.Add(/*here create new parameter*/);
RadSource.SetBinding(twc.RadDomainDataSource.DomainContextProperty,
               new swd.Binding(){ Path = new swd.PropertyPath("context") } );
RadSource.AutoLoad = true;
RadSource.Load();
That's work.

But when I try to change it back:
1 RadSource.AutoLoad = false;
2 RadSource.DomainContext = null;
3 RadSource.QueryName = "GetPersonSetQuery";
4 RadSource.QueryParameters.Clear();
5 RadSource.SetBinding(/*...*/);
6 RadSource.AutoLoad = true;
7 RadSource.Load();
I have got an error in the 4th line:
"System.NullReferenceException in Telerik.Windows.Controls.RadDomainDataSource.PrepareParameterValue(ParameterInfo serverParameter)".
I have tried to swap the 3rd and 4th lines. It has been useless.

Attempt to reinitialize property QueryParameters
RadSource.SetValue(RadDomainDataSource.QueryParametersProperty,new QueryParameterCollection());
no results, cause "Cannot change read-only DependencyProperty".

How can I clear or reset this property or change Query+Parameters to Query?

2 Answers, 1 is accepted

Sort by
0
Accepted
Nedyalko Nikolov
Telerik team
answered on 01 Feb 2011, 01:44 PM
Hi Nikita,

Sorry for the late answer.
RadDomainDataSource control uses special logic to handle all changes in every critical parameter like DomainContext, QueryName, QueryParameters and etc. However we have a solution for this problem, actually the solution is part of the xaml nature of this control (we cannot assume that any parameter or property will be set when we handle another property change). Your example perfectly illustrates this - when you set QueryName we perform a check that method with same name exists on the server, but we also check if QueryParameters are correct (by type and by name). Same check is performed when QueryParameters are changed. And what happens when you set QueryName there is no correct QueryParameters and vice versa. Now the solution - RadDomianDataSource implements ISupportInitialize interface which will help with such problems - just call radDomainDataSource.BeginInit() before and radDomainDataSource.EndInit() after initialization of the control.

this.rdds.BeginInit();
this.rdds.AutoLoad = false;
this.rdds.QueryName = "GetCustomers";
this.rdds.QueryParameters.Clear();
this.rdds.AutoLoad = true;
this.rdds.EndInit();


Let me know if there is something unclear or if this doesn't help.

All the best,
Nedyalko Nikolov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Nikita
Top achievements
Rank 1
answered on 01 Feb 2011, 11:58 PM
Hi Nadyalko,
it's works. Thanks a lot!
Tags
DomainDataSource
Asked by
Nikita
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Nikita
Top achievements
Rank 1
Share this question
or