VirtualQueryableCollectionView calling DB multiple times.

6 posts, 0 answers
  1. Philipp
    Philipp avatar
    5 posts
    Member since:
    Feb 2016

    Posted 02 May Link to this post

    Hi,

    the ItemsLoaded event is called using an IEnumerable of the items that were loaded. If the underlying collection of the VirtualQueryableCollectionView is an IQueryable (e.g. a DB-Queryable) and I want to iterate over the loaded elements, another DB-Query is created. The expected behavior should be, that it is only enumerated once and the list is sent in the ItemsLoaded event.

    Best regards,

    Philipp

  2. Stefan X1
    Admin
    Stefan X1 avatar
    518 posts

    Posted 04 May Link to this post

    Hi Philipp,

    Can you please clarify what query is created for the second time? Did you mean that the ItemsLoaded event is initially called more than once? If the value set to the LoadSize property of VQCV is less than the count of the visible items in the viewport, such behavior would be expected.

    All the best,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Philipp
    Philipp avatar
    5 posts
    Member since:
    Feb 2016

    Posted 04 May Link to this post

    Hi Stefan,

    no, the event is correctly triggered, but the event args contain an IEnumerable. And this enumerable is enumerated twice. Once by the virtual collection view and once by me, when I want to access the items. As I use the virtual collection view with an IQueryable, it also creates twodatabase queries.

    Best regards,

    Philipp

  5. Stefan X1
    Admin
    Stefan X1 avatar
    518 posts

    Posted 09 May Link to this post

    Hi Philipp,

    Thanks for the update.

    As such behavior is not known to us, can you please share some details on how are you enumerating the items, so that a second query is triggered. Moreover, what behavior do you expect from the VirtualQueryCollectionView, as it correctly creates only one query and works as expected?

    Regards,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Philipp
    Philipp avatar
    5 posts
    Member since:
    Feb 2016

    Posted 09 May Link to this post

    Hi Stefan,

    I attach an event handler to the ItemsLoaded event and just create a list of them, like this:

    private void OnItemsLoaded(object sender, VirtualQueryableCollectionViewItemsLoadedEventArgs args)
    {
        var elements = args.Items.Cast<DynamicEntity>().ToList();
    }

    When I take a look at the source of the VirtualQueryableCollectionView, how the event is handled (using Resharper) you see this:

     

    private void LoadItemsIfNeededForIndex(int index)
        {
    ...
          this.Load(num, (IEnumerable) QueryableExtensions.Sort(QueryableExtensions.Where(this.Query, this.FilterDescriptors), this.SortDescriptors).Skip(num).Take(count));
        }
     
        public void Load(int startIndex, IEnumerable items)
        {
          VirtualQueryableCollectionView.Dispatcher.BeginInvoke((Action) (() => this.LoadItems(startIndex, items)));
        }
     
        private void LoadItems(int startIndex, IEnumerable items)
        {
    ...
          foreach (object obj in items)
          {
    ...
          }
          if (this.ItemsLoaded != null)
            this.ItemsLoaded((object) this, new VirtualQueryableCollectionViewItemsLoadedEventArgs()
            {
              StartIndex = startIndex,
              Items = items
            });
    ...
        }

    The LoadItems-Method iterates over the items, and then the same enumerable is sent through the event. So when I iterate the elements to a list, I iterate them again. The expectation is that the LoadItems-Method first iterates them to a list, and iterates the list, and also calls the changed method with that list.

    Regards,

    Philipp

     

  7. Stefan X1
    Admin
    Stefan X1 avatar
    518 posts

    Posted 12 May Link to this post

    Hello Philipp,

    Thanks for the update.

    I managed to reproduce this behavior at my side, so I have logged it in our backlog. You can track its state in the Feedback Portal: item.

    I have also updated your Telerik points as a gratitude for your suggestion for improving the VQCV.

    All the best,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready