views:

292

answers:

2

Hello,

I am working on a generic OData provider to go against a custom data provider that we have here. Thsi is fully dynamic in that I query the data provider for the table it knows. I have a basic storage structure in place so far based on the OData sample code.

My problem is: OData supports queries and expects me to hand in an IQueryable implementation. On the lowe rside, I dont have any query support. Not a joke - the provider returns tables and the WHERE clause is not supported. Performance is not an issue here - the tables are small. It is ok to sort them in the OData provider.

My main problem is this.

  • I submit a SQL statement to get out the data of a table. The result is some sort of ADO.NET data reader here.
  • I need to expose an IQueryable implementation for this data to potentially allow later filtering.

Any ide ahow to best touch that? .NET 3.5 only (no 4.0 planned for some time). I was seriously thinking of creating dynamic DTO classes for every table (emitting bytecode) so I can use standard LINQ. Right now I am using a dictionary per entry (not too efficient) but I see no real way to filter / sort based on them.

A: 

Pablo Castro, one of the main voices behind OData says that delivering an OData service without the querying capability is completely within consistent within their intent. See this blog post.

This is one of the reasons I really wish they would implement a "search" link in the OData response so that a client application could determine if querying capabilities were available or not. Something like OpenSearch.

<Link rel="search" type="application/ODataQuery+xml" href="QueryMetadata.xml"/>

That way, a client can easily discover if search is implemented or not.

Darrel Miller
+1  A: 

If you're OK with executing the query inside your OData provider, you can simply load your data into a List of T (T being the type of the entity) and then simply return list.AsQueryable(). This will return a LINQ to Objects queryable, which provides full support for all query options and is based on the in-memory storage (the list). Note that for this to work correctly your IDataServiceQueryProvider.IsNullPropagationRequired must return true (as LINQ to Objects requires nulls to be correctly propagated through the query). Also if you set CanReflectOnInstanceProperty anywhere to false, you will need to do some query rewrite. If that's the case take a look at this post here for explanation on how properties are accessed.

Vitek Karas MSFT