Change QueryableDomainServiceCollectionView<T> bound to grid

6 posts, 0 answers
  1. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 07 Feb 2011 Link to this post

    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;
            }
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Feb 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Feb 2011 Link to this post

    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>>
  5. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 07 Feb 2011 Link to this post

    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
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Feb 2011 Link to this post

    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>>
  7. Frank
    Frank avatar
    12 posts
    Member since:
    May 2011

    Posted 21 Jun 2011 Link to this post

    *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)
Back to Top
DevCraft banner