I am using oData for a web api project. This is my code :
[HttpGet]
[EnableQuery]
[Route("sessions")]
public IQueryable<Session> Get()
{
var sessions = this.sessionRepository.GetAllSessions();
return sessions.AsQueryable();
}
public class Session
{
public long Id {get;set;}
public string Name {get;set;}
}
This is working well :
When I call the api like this mydomain/api/sessions, I get all the sessions When I call the api like this mydomain/api/sessions?$filter=Name eq 'session test', I get only the sessions which has the name equals to 'session test'.
The problem with this code, is that whatever the request performed by the user (no filter, filter, top, or anything else), a first "select *" is performed in db and then with the QueryableAttribute from oData, a filter is performed on the results got from the first big request "select *". My question is the following : is it possible to perform the query given by the user directly in the db and not doing first the select * and then performs the filter on this result.
Thanks in advance for your help.