I finally found out what is probably wrong, but I don't know how to fix it.
If I'm trying to pass parameter queries like that:
http://(...)/People?$filter=SomeProperty eq 'Foo'
In my WebAPI controller method after applying OData Query Options to my query, that is:
IQueryable<People> queryResults = (IQueryable<People>)queryOptions.ApplyTo(query);
In queryResults there is a fragment like that:
WHERE (`Project1`.`SomeProperty` = @p__linq__0)
And everything works fine. But when I pass query like that:
http://(...)/People?$filter=contains(SomeProperty, 'Foo')
In queryResults I can see that:
WHERE (`Project1`.`SomeProperty` LIKE '%p__linq__0%')
And there is always no results.
I don't know if I understand it correctly, but it seems like it is looking for SomeProperty values containing text 'p__linq__0' instead of looking for values that contains the value of p__linq__0 (which is 'Foo').
Thank you for your response, @QianLi.
My controller looked like that:
public class PeopleController : ApiController
{
readonly PeopleContext _context = new PeopleContext();
public PageResult<People> Get(ODataQueryOptions<People> queryOptions)
{
var query = _context.People.OrderBy(x => x.SomeProperty1);
var queryResults = (IQueryable<People>)queryOptions.ApplyTo(query);
long cnt = 0;
if (queryOptions.Count != null)
cnt = long.Parse(Request.Properties["System.Web.OData.TotalCount"].ToString());
return new PageResult<People>(queryResults, null, cnt);
}
}
(This weird workaround with 'cnt' is explained there: Items count in OData v4 WebAPI response)
But now I give up on using Count and I changed controller implementation to something like described by you:
[EnableQuery]
public class PeopleController : ODataController
{
public IHttpActionResult Get()
{
var query = _context.People.OrderBy(x => x.SomeProperty1);
return Ok(query);
}
}
And it works the same as before - filter queries with eq, lt etc. works fine, contains doesn't work at all.
Edit: I know! The problem can be a result of using this fix: http://www.nuget.org/packages/Patches.System.Web.OData/5.3.0-datetimefixes instead of official OData library. But I need this datetimefixes very much...
GET
request to the entity set that you want to filter? – Yi Ding - MSFT