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

VirtualQueryableCollectionView calling DB multiple times.

5 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Philipp
Top achievements
Rank 1
Philipp asked on 02 May 2016, 09:56 AM

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

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 04 May 2016, 03:02 PM
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.
0
Philipp
Top achievements
Rank 1
answered on 04 May 2016, 03:08 PM

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

0
Stefan
Telerik team
answered on 09 May 2016, 11:15 AM
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.
0
Philipp
Top achievements
Rank 1
answered on 09 May 2016, 11:59 AM

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

 

0
Stefan
Telerik team
answered on 12 May 2016, 08:51 AM
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.
Tags
GridView
Asked by
Philipp
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Philipp
Top achievements
Rank 1
Share this question
or