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
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
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
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
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
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