0

I have existing internal OData service.

The goal is to create new service for external users.

I tried to create IQueryable using odata client and then expose it using WebApi with filter added.

//autogenerated by T4 from odata client
public partial class Container : Microsoft.OData.Client.DataServiceContext
{
   ...
   public DataServiceQuery<Model> Models {...}
}
//minified version of generated model
public class Model
{
    public int Type { get; set; }
    public string Test { get; set; }
}
//api controller
private Container client;
[EnableQuery]
public IQueryable<Model> Get()
{
   return client.Models.Where(i=>i.Type==123);
}

Just that simple. Yet its not working. Looks like QueryProvider from ms odata client does not support expressions built by ms webapi odata.

This code is working

client.Models.Where(i=>i.Type==123).Where(i=>i.Test.Contains("qwe")).ToList()

This request does not

http://localhost:44301/Model?$filter=contains(Test,'qwe')

Exception

The expression (IIF((($it.Test== null) OrElse False), null, Convert($it.Test.Contains(\"qwe\"))) == True) is not supported.

I like the idea itself since i dont need to cache data but only provide query.

Is there any way to make this work?

Right now only option i see is to write custom QueryProvider.

random
  • 1
  • 2
  • What is the type of the `client` variable? What is the type of the `Models` property? – lencharest Apr 28 '16 at 05:22
  • Thanks for the additional detail. But your examples of what is working and not working seem reversed with respect to the rest of the post. Am I missing something? – lencharest Apr 28 '16 at 17:23
  • Examples are correct. C# client with contains working fine. Problems starts when im trying to return that iqueryable from new service and query it with odata. C# example using 1st service. And odata url example 2d service. – random Apr 28 '16 at 17:50

0 Answers0