Telerik blogs
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()
    {
        InitializeComponent();
 
        var service = new NorthwindEntities(new Uri("http://services.odata.org/Northwind/Northwind.svc/"));
 
        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!
            this.dataServiceCollection.Load(this.query);
 
            while (this.dataServiceCollection.Continuation != null)
            {
                this.dataServiceCollection.Load(context.Execute<T>(this.dataServiceCollection.Continuation.NextLinkUri));
            }
 
            // Group data in-memory.
            return this.dataServiceCollection.AsQueryable().GroupBy(this.GroupDescriptors);
        }
 
        return base.CreateView();
    }
}

The result:


Enjoy!

Download

WPF
About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Related Posts

Comments

Comments are disabled in preview mode.