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

[Solved] Grid and WCF Data Services OData Binding

7 Answers 169 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 27 Jun 2011, 03:46 PM
I've read this somewhat old post - Binding Telerik Grid for ASP.NET MVC to OData.

It seems like OData binding support isn't really in the grid component yet for MVC.  If I try to use the default sorting, filtering, and paging I get runtime errors when the grid attempts to requery the data set.  The error is:

The orderby query option cannot be specified after the select query option.
This happens upon clicking a column header to apply a sort to the data.

7 Answers, 1 is accepted

Sort by
0
Dimitar
Top achievements
Rank 1
answered on 02 Aug 2011, 03:19 PM
I had a similar issue and after digging around the source, I don't think this can be fixed if your scenario is the same as mine. I was doing a 'select' to transform my entities into simpler, flat objects. This does not actually request any data from the service, but the resulting IQueryable won't allow orderby (probably other stuff too) as the new 'objects' in the Queryable don't have corresponding entities in the service.

I ended up using the service entities without 'select'-ing into new objects, but if that's not an option, I believe you should be able to use .ToList() and bind to the resulting collection.
0
Kevin
Top achievements
Rank 1
answered on 02 Aug 2011, 03:35 PM
My problem is that I have common queries to the WCF data service defined in a helper class, and methods that make use of those queries. It just seems like either Telerik isn't using them right or the .NET LINQ queries generated for data services aren't being built properly.  For example, I might have something like this:

private IQueryable<SomeObject> EligibleObjects {
    get {
        return from o in Context.SomeEntities
             where o.SomeProperty == 1
             select o;
    }
}

Then other methods will call that property and add filter criteria, etc.  It allows me to create "canned" queries and not have to duplicate logic that can sometimes be rather complex.  The trouble is that the URI for data services that is generated is not in a format that WCF can work with.
0
Dimitar
Top achievements
Rank 1
answered on 02 Aug 2011, 03:53 PM
Can you try this so you can avoid the select:

return Contect.SomeEntities.Where(o => o.SomeProperty == 1)
0
Kevin
Top achievements
Rank 1
answered on 02 Aug 2011, 04:04 PM
It's the same error as in my original post.  If I remember correctly when I tested this a while back, the problem is that OData only allows you to do things in a very specific order.  What's happening is the Telerik control is being given a data query that already has a select, from, where, potentially order by, and so on.  And then if you want to filter or sort it's using that query as its base and applying the user-selected options.  So in the end it's running multiple selects (logically anyway) against the WCF data service.

The solution would be for the Telerik control to better structure the query.  As I mentioned this might be a LINQ thing and not Telerik's fault.  Also for almost every other data source the order of the query structure doesn't matter.
0
Dimitar
Top achievements
Rank 1
answered on 02 Aug 2011, 04:43 PM
When I was playing around with some other stuff, I managed to use the GridDataProcessor to apply the Grid's sorting/filtering query to a collection similar to what's happening in the GridActionAttribute, but this won't solve the 'specific order' problem of OData since you'll need to do it before the select in your property. I'm starting to hate WCF DS/OData
0
Kevin
Top achievements
Rank 1
answered on 02 Aug 2011, 04:47 PM
Yeah +1 on the WCF Data Services hate.  I'm thinking of just using MVC to come up with a RESTful service layer exposing JSON data.
0
Dimitar
Top achievements
Rank 1
answered on 02 Aug 2011, 05:32 PM
REST for the win. I wish I had a choice for our project, but I'm not the one dictating these things:)
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Dimitar
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Share this question
or