I used ObservableCollection type of object . I tried Filter by the following code

public ObservableCollectionView<Person> SampleEntries { get; set; }


private void ApplyFilter(int age)
    {
        SampleEntries.Filter = (entry => entry.Age > age ) ;
        // converting ObservableCollection into AsQueryable
        var source = this.SampleEntries.AsQueryable();
        //Shows the value as Destination array was not long enough
        var source1 = source.OrderByDescending(x => x.Id);

    }

After applying filter , tried to sort the column , it throws the

Exception  : "System.ArgumentException was unhandled by user code" Message=Destination array was not long enough. Check destIndex and length, and the array's lower bounds.

Note: I need to know why this code is not working. We already have other ways to fix to this problem.

Update: The ObservableCollectionView class can be found in the MyToolkit library.

2

There are 2 best solutions below

1
On

Have you istancied the collection first?

2
On

It seems to me that ObservableCollectionView was not designed to be directly used with Linq. If you just need to sort items in ObservableCollectionView in descending order you should use Order and Ascending properties. For example:

    ...
    SampleEntries.Filter = (entry => entry.Age > age ) ;
    SampleEntries.Order= x => x.Id;
    SampleEntries.Ascending = false; 
    ...

If you really need to use Linq try this:

    ...
    var source = this.SampleEntries.AsQueryable().ToList();
    var source1 = source.OrderByDescending(x => x.Id);
    ...