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

Change QueryableDomainServiceCollectionView<T> bound to grid

5 Answers 159 Views
DomainDataSource
This is a migrated thread and some comments may be shown as answers.
Licenses
Top achievements
Rank 1
Licenses asked on 07 Feb 2011, 11:18 AM
Hello,

I define a property in the viewmodel that is a QueryableDomainServiceCollectionView<T>. This property has change notification so that the grid that is bound to it gets notified whenever this QDSCV is changed. In the viewmodel there is a Load function that creates the EntityQuery, sets the parameters and creates a new QueryableDomainServiceCollectionView<T>. The last step in this function sets the AutoLoad to true, so that the QDSCV keeps synced with the group-, filter- and sortdescriptors.

When the user requests a refresh of the grid, then the Load function is called again. When debugging I noticed that the old QDSCV is still loading data. To resolve this I wrote the QDSCV property on the viewmodel like this:

private QueryableDomainServiceCollectionView<TaskListDto> _taskListCollectionView;
        public QueryableDomainServiceCollectionView<TaskListDto> TaskListCollectionView
        {
            get { return _taskListCollectionView; }
            set
            {
                if (_taskListCollectionView == value)
                    return;
                if (_taskListCollectionView != null) _taskListCollectionView.Cleanup();
                _taskListCollectionView = value;
                NotifyPropertyChanged("TaskListCollectionView");
            }
        }

The Cleanup-function doest the following:
public void Cleanup()
        {
            base.Dispose();
            this.AutoLoad = false;
            this.GroupDescriptors.Clear();
            this.FilterDescriptors.Clear();
            this.SortDescriptors.Clear();
        }

This way of working resolves the issue that the grid loads the data twice from the server, but some other issues still remain. The Data_Loaded event of the RadGridView is thrown a lot of times. Ans when I debug, I can clearly see that the data involved is still data of the old QDSCV.

Is there maybe a better way to re-load data with a QDSCV? Important is that the queryparameters can be different from the previous load. So I create a new EntityQuery, and based on that I create a new QDSCV because there is no way to change the EntityQuery for the same QDSCV (is this true?).

public void LoadTasks(){
            var query = _context.SearchTasksQuery(CustomerId, CurrentEmployeeId, CurrentUserId.Value, SearchString, SearchDeadline, SearchUrgent, SearchRecent, CategoryId, FinishedTasks, ShowTasksOfOthers);
                TaskListCollectionView = new QueryableDomainServiceCollectionView<TaskListDto>(_context, query);
                TaskListCollectionView.SortDescriptors.Add(new Telerik.Windows.Data.SortDescriptor { Member = "SortableDeadlineDate", SortDirection = System.ComponentModel.ListSortDirection.Ascending });
                TaskListCollectionView.GroupDescriptors.Add(new Telerik.Windows.Data.GroupDescriptor { Member = "WorkflowCategoryDescription", SortDirection = System.ComponentModel.ListSortDirection.Ascending });
                TaskListCollectionView.AutoLoad = true;
        }

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 07 Feb 2011, 11:49 AM
Hello Sodi We,

Important is that the queryparameters can be different from the previous load. So I create a new EntityQuery, and based on that I create a new QDSCV because there is no way to change the EntityQuery for the same QDSCV (is this true?).

You can try to create a single instance of both the EntityQuery and the QueryableDomainServiceCollectionView. Then each time a query parameter changes, you can update its value by using the EntityQuery.Parameters collection. Maybe this will help in avoiding the re-creation of the QDSCV each time. Let me know if this does not help.

Best wishes,
Ross
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
Rossen Hristov
Telerik team
answered on 07 Feb 2011, 12:00 PM
Hi Sodi We,

I forgot to mention that you will have to call the Load method after you update EntityQuery.Paramaters with the new values.

Best wishes,
Ross
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
Licenses
Top achievements
Rank 1
answered on 07 Feb 2011, 12:06 PM
I will try this, but working with the EntityQuery.Parameters collection seems very unsafe to me. It's working with a dictionary of strings and objects. So the compiler cannot check whether the name provided is correct, or whether the type of the parameter provided is correct. When working with context.GetEmployees(true), the compiler checks that the parameter type is a boolean, and there is no need for the developer to give a name to the parameter. So when changes to the query on the server have taken place, the compiler cannot check if all calls of this query are still correct.

Is there no better way to change the query parameters? Or to bind a grid's itemssource to another QDSCV?

Kind regards,
Sodi we
0
Rossen Hristov
Telerik team
answered on 07 Feb 2011, 01:44 PM
Hi Sodi We,

I am afraid that that is the only way. Maybe you are trying to achieve something that is not possible with the QDSCV. My suggestions would be to develop your own collection view which will take into account your particular specific needs and you will have full controls over it.

All the best,
Ross
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
Frank
Top achievements
Rank 1
answered on 21 Jun 2011, 05:01 PM
*Quote*
Hello Sodi We,

Important is that the queryparameters can be different from the previous load. So I create a new EntityQuery, and based on that I create a new QDSCV because there is no way to change the EntityQuery for the same QDSCV (is this true?).

You can try to create a single instance of both the EntityQuery and the QueryableDomainServiceCollectionView. Then each time a query parameter changes, you can update its value by using the EntityQuery.Parameters collection. Maybe this will help in avoiding the re-creation of the QDSCV each time. Let me know if this does not help.

Best wishes,
Ross 
the Telerik team
*Quote*

Solved the problem for me thanks!

Best wishes,
Julian

(Just replied, so that somebody else with this problem see, that it is working)
Tags
DomainDataSource
Asked by
Licenses
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Licenses
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Share this question
or