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

Force inital load of VirtualQueryableCollectionView

2 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 15 Apr 2015, 07:43 PM

I create a VirtualQueryableCollectionView using the following method, the SourceCollection of the view is empty.  Is there any way to force an initial load?

 

public VirtualQueryableCollectionView GetVirtualQueryableCollectionView(int loadsize,
    List<String> includes, Func<T, bool> whereClause,
    Func<T, Object> orderBy, bool orderByIsDesc = false,
    Func<T, Object> thenBy = null, bool thenByIsDesc = false)
{
    ObjectQuery<T> q = Query(CreateContext());
    if (includes != null)
    {
        foreach (var include in includes)
        {
            q = q.Include(include);
        }
    }
    if (whereClause != null)
    {
        if (orderBy != null)
        {
            if (orderByIsDesc)
            {
                if (thenBy != null)
                {
                    if (thenByIsDesc)
                    {
                        q.Where(whereClause).OrderByDescending(orderBy).ThenByDescending(thenBy);
                    }
                    else
                    {
                        q.Where(whereClause).OrderByDescending(orderBy).ThenBy(thenBy);
                    }
                }
                else
                {
                    q.Where(whereClause).OrderByDescending(orderBy);
                }
            }
            else
            {
                if (thenBy != null)
                {
                    if (thenByIsDesc)
                    {
                        q.Where(whereClause).OrderBy(orderBy).ThenByDescending(thenBy);
                    }
                    else
                    {
                        q.Where(whereClause).OrderBy(orderBy).ThenBy(thenBy);
                    }
                }
                else
                {
                    q.Where(whereClause).OrderBy(orderBy);
                }
            }
        }
        else
        {
            q.Where(whereClause);
        }
    }
    else if (orderBy != null)
    {
        if (orderByIsDesc)
        {
            if (thenBy != null)
            {
                if (thenByIsDesc)
                {
                    q.OrderByDescending(orderBy).ThenByDescending(thenBy);
                }
                else
                {
                    q.OrderByDescending(orderBy).ThenBy(thenBy);
                }
            }
            else
            {
                q.OrderByDescending(orderBy);
            }
        }
        else
        {
            if (thenBy != null)
            {
                if (thenByIsDesc)
                {
                    q.OrderBy(orderBy).ThenByDescending(thenBy);
                }
                else
                {
                    q.OrderBy(orderBy).ThenBy(thenBy);
                }
            }
            else
            {
                q.OrderBy(orderBy);
            }
        }
    }
    var view = new VirtualQueryableCollectionView(q)
    {
        LoadSize = loadsize
    };
 
    return view;
}
 

 

​

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 17 Apr 2015, 03:10 PM
Hello Steve,

Please note that ObjectQuery is immutable and the queries you build are not applied with the current approach, since the where clause returns a new instance. You can check the following implementation of the method and you will notice that the where clause is properly applied:
public MainWindow()
{
    InitializeComponent();
 
    Func<Customer, bool> where = (c)=>
        {
            return c.ContactName.Contains("afadsfasf");
        };
 
    this.clubsGrid.ItemsSource = GetVirtualQueryableCollectionView<Customer>(50, null, where, null);
}
 
public VirtualQueryableCollectionView GetVirtualQueryableCollectionView<T>(int loadsize,
    List<String> includes, Func<Customer, bool> whereClause,
    Func<Customer, Object> orderBy, bool orderByIsDesc = false,
    Func<Customer, Object> thenBy = null, bool thenByIsDesc = false)
{
    var context = new northwindEntities();
    ObjectContext oc = ((IObjectContextAdapter)context).ObjectContext;
 
    ObjectQuery<Customer> q = new ObjectQuery<Customer>("Customers", oc);
 
    var query = q.Where(whereClause);
 
    var view = new VirtualQueryableCollectionView(query.OrderBy(c => c.CustomerID))
    {
        LoadSize = loadsize
    };
 
    return view;
}

I hope this makes sense.

Best Regards,
Stefan
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Steve
Top achievements
Rank 1
answered on 17 Apr 2015, 03:22 PM
Perfect,  thanks so much!
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Steve
Top achievements
Rank 1
Share this question
or