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

Data virtualization and asynchrounous loading, search and filtering with Entity Framework

0 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 16 Apr 2020, 10:03 AM

I am doing data virtualization using VirtualQueryableCollectionView.

I pass there IQueryable from EF.

var db = new ProductionContext();
IQueryable cards = db.Cards.OrderBy(x => x.CardId);
var view = new VirtualQueryableCollectionView(cards) { LoadSize = 50 };
cardsRadGridView.ItemsSource = view;

Its works fine. But how to make it asynchronous? (asynchronous loading, search, filtering) I searched for examples but found only examples for WCF like bellow

https://www.telerik.com/blogs/telerik-data-virtualization-wcf-ria-services-and-visual-studio-async-ctp?_ga=2.125533513.2135094116.1586865074-1480584776.1567419497

I tried to do the same for the EF

var db = new ProductionContext();
IQueryable cards = db.Cards.OrderBy(x => x.CardId);
 
Loaded += async (o, args) =>
{
    var view = new VirtualQueryableCollectionView<Card>
    {
        LoadSize = 50,
        VirtualItemCount = await TaskEx.Run(() => cards.Count())
    };
 
    view.FilterDescriptors.CollectionChanged += async (s, e) =>
    {
        view.VirtualItemCount = await
            TaskEx.Run(() => cards.Where(view.FilterDescriptors).Count());
    };
 
    view.FilterDescriptors.ItemChanged += async (s, e) =>
    {
        view.VirtualItemCount = await
            TaskEx.Run(() => cards.Where(view.FilterDescriptors).Count());
    };
 
    view.ItemsLoading += async (s, e) =>
    {
        var queryToLoad = cards
            .Sort(view.SortDescriptors)
            .Where(view.FilterDescriptors)
            .Skip(e.StartIndex)
            .Take(e.ItemCount);
 
        cardsRadGridView.IsBusy = true;
        view.Load(e.StartIndex, await TaskEx.Run(() => queryToLoad.ToIList()));
        cardsRadGridView.IsBusy = false;
    };
 
    cardsRadGridView.ItemsSource = view;
};

but it does not work(

Where can one find a good example of implementing this?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Denis
Top achievements
Rank 1
Share this question
or