cannot convert from 'Telerik.Windows.Data.QueryableCollectionView' to 'System.Linq.IQueryable'

3 posts, 0 answers
  1. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 26 Jul 2012 Link to this post

    I have a GridView that is bound to a QueryableCollectionView. The QueryableCollectionView is constructed from an ObservableCollection, which is populated in code.  (So there's no messing about with LINQ to SQL ORMS, etc.)

    I have a command implemented in the ViewModel (bound to a button and to a function key, but that's not important), that needs to check to see if any of the records contained in the grid have certain values in a certain field.

    I'd thought I'd be able to do a simple LINQ query on the QueryableCollectionView, but it doesn't seem to work. Even the simplest won't compile.

    This:

    var customerids =
        from c in customersQueryView
        select c.customerid;

    Results in: Instance argument: cannot convert from 'Telerik.Windows.Data.QueryableCollectionView' to 'System.Linq.IQueryable'

    This:

    var customerids =
        from c in customersQueryView.AsQueryable()
        select c.customerid;

    Results in: Cannot convert lambda expression to type 'Telerik.Windows.Data.SelectDescriptorCollection' because it is not a delegate type.

    The only workaround I've been able to find is to iterate through all the records with a foreach(), which results in considerably less clear code.
  2. Tim Weckx
    Tim Weckx avatar
    4 posts
    Member since:
    Jul 2012

    Posted 27 Jul 2012 Link to this post

    Jeff,

    The Telerik.Windows.Data.QueryableCollectionView does not implement System.Linq.IQueryable. To get the behaviour you want, you first need to call .AsQueryable() or .OfType<>() if you know the type of objects contained in the collection. This will allow you to use Linq statements on the collection.

    Telerik.Windows.Data.QueryableCollectionView collection = new Telerik.Windows.Data.QueryableCollectionView();
     
    // either
    IQueryable queryable = collection.AsQueryable();
    // or
    IEnumerable<> queryable = collection.OfType<>();

    Tim

  3. UI for WPF is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    100 posts
    Member since:
    Apr 2008

    Posted 27 Jul 2012 Link to this post

    The first choice you offer, using .AsQueryable(), I'd tried, and encountered the error I'd included in my original post.

    The second, using .OfType<>(), worked.  Thanks.
Back to Top