Force inital load of VirtualQueryableCollectionView

3 posts, 1 answers
  1. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 15 Apr 2015 Link to this post

    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. Answer
    Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 17 Apr 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 17 Apr 2015 in reply to Stefan X1 Link to this post

    Perfect,  thanks so much!
Back to Top