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.