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

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

2 Answers 251 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 26 Jul 2012, 02:50 PM
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 Answers, 1 is accepted

Sort by
0
Tim Weckx
Top achievements
Rank 2
answered on 27 Jul 2012, 10:09 PM

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

0
Jeff
Top achievements
Rank 1
answered on 27 Jul 2012, 10:24 PM
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.
Tags
GridView
Asked by
Jeff
Top achievements
Rank 1
Answers by
Tim Weckx
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Share this question
or