0

I have a WCF Data Service and it gets its data from dinamically created objects, like this:

List<UObject> list=new List<UObject>();
for(int i=0;i<20;i++)
{
list.Add(new UObject());
}

For the clients it has to be accessible as a queryable method, so I use this code:

[WebGet]
public IQueryable<UObject> GetObjects()
{
return list.Where(e=>e.Item>=2).AsQeryable<UObject>();
}

The problem is that the objects are in a List and it cannot be queried with Take or Skip commands, it simply returns the entire IEnumerable (I presume).

So when I call it from an Android client:

consumer.callFunction("GetObjects").top(10).execute();

I get the following exception:

org.odata4j.exceptions.BadRequestException: Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource.

How should I implement a queryable list? Is it possible or I can use it only against Entity Framework DbSets?

Nestor
  • 8,194
  • 7
  • 77
  • 156

1 Answers1

0

Adding an attribute may resolve this problem: [Queryable], or [EnableQuery] if you are using a recent webApi bits

[WebGet]
[Queryable]
public IQueryable<UObject> GetObjects()
{
return list.Where(e=>e.Item>=2).AsQeryable<UObject>();
}
Tan Jinfu
  • 3,327
  • 1
  • 19
  • 20
  • I added the WebApi package and used this attribute but I'm still getting the exception (I tested in browser with this: http://localhost:12500/DataService.svc/GetObjects?$top=3 and it also throws exception) – Nestor Apr 30 '14 at 11:10
  • What is the request URI? – Tan Jinfu May 01 '14 at 11:54
  • What do you mean? The URI is localhost:12500/DataService.svc/GetObjects?$top=3 It is a regular OData request. Should I check anything else? – Nestor May 03 '14 at 16:32