In WCF Data Services there is a set of not supported LINQ queries and you will get NotSupportedException if you try to group RadGridView for WPF bound directly to such IQueryable or through QueryableCollectionView/VirtualQueryableCollectionView. For example:

public partial class MainWindow : Window
    public MainWindow()
        var service = new NorthwindEntities(new Uri(""));
        DataContext = new VirtualQueryableCollectionView(service.Customers) { LoadSize = 10 };

There is an easy way to enable this and to achieve your goal you will need to inherit from VirtualQueryableCollectionView, override CreateView() method, download all the data from the service if the collection is grouped and group the data on the client:

public class CustomVirtualQueryableCollectionView<T> : VirtualQueryableCollectionView
    private readonly IQueryable<T> query;
    private readonly DataServiceContext context;
    private readonly DataServiceCollection<T> dataServiceCollection;
    public CustomVirtualQueryableCollectionView(DataServiceContext context, IQueryable<T> source)
        : base(source)
        this.context = context;
        this.query = source;
        this.dataServiceCollection = new DataServiceCollection<T>();
    protected override IQueryable CreateView()
        if (this.IsGrouped)
            // Load all data from the WCF Data Service since GroupBy is not supported!
            while (this.dataServiceCollection.Continuation != null)
            // Group data in-memory.
            return this.dataServiceCollection.AsQueryable().GroupBy(this.GroupDescriptors);
        return base.CreateView();

The result:


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Related Posts