{"action":"created","issue":{"url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/413","labels_url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/413/labels{/name}","comments_url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/413/comments","events_url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/413/events","html_url":"https://github.com/TrevorPilley/MicroLite/issues/413","id":108546267,"number":413,"title":"Thoughts on OData queries","user":{"login":"djanosik","id":858180,"avatar_url":"https://avatars.githubusercontent.com/u/858180?v=3","gravatar_id":"","url":"https://api.github.com/users/djanosik","html_url":"https://github.com/djanosik","followers_url":"https://api.github.com/users/djanosik/followers","following_url":"https://api.github.com/users/djanosik/following{/other_user}","gists_url":"https://api.github.com/users/djanosik/gists{/gist_id}","starred_url":"https://api.github.com/users/djanosik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djanosik/subscriptions","organizations_url":"https://api.github.com/users/djanosik/orgs","repos_url":"https://api.github.com/users/djanosik/repos","events_url":"https://api.github.com/users/djanosik/events{/privacy}","received_events_url":"https://api.github.com/users/djanosik/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-27T16:28:57Z","updated_at":"2015-09-28T10:50:07Z","closed_at":"2015-09-27T18:02:35Z","body":"One of reasons why I've decided to use MicroLite is the support for OData queries. We use them a lot in our applications. However there are two things I find disappointing about MicroLite's OData support.\r\n\r\n1. It's built around the `SqlBuilder`. I think it will always be somehow limited when compared to writing queries in SQL. For example: you can't create efficient query for `SingleAsync` method; you can't select from TVF; etc. Yes, it can be fixed, but that's not the point. It should be possible to use OData queries with \"every\" SQL query you can imagine :)\r\n\r\n2. It's tied to WebAPI extensions. I think it should be available to everyone, not just to users who choose to build their controllers on top of the `MicroLiteODataApiController`.\r\n\r\nSo, I am thinking about something like this:\r\n\r\n```c#\r\npublic async Task<IOData<Record>> GetRecords(ODataQueryOptions<Record> odata)\r\n{\r\n    var query = new ODataQuery(\r\n        \"SELECT * FROM Whateever WHERE Id > @p0 AND @odata\",\r\n        10245, odata\r\n    );\r\n\r\n    return await session.ODataAsync<Record>(query);\r\n}\r\n```\r\n- The `ODataQuery` is derived from `SqlQuery`. It transforms the `@odata` parameter to other `WHERE` and `ORDER BY` clauses. It has some limitations, but it might work.\r\n\r\n- The `ODataAsync` method will execute information provided by the `ODataQuery`. It will make sure that the returned result conforms to the OData query. It will take into account parameters like `inlinecount`, etc.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/comments/143707871","html_url":"https://github.com/TrevorPilley/MicroLite/issues/413#issuecomment-143707871","issue_url":"https://api.github.com/repos/TrevorPilley/MicroLite/issues/413","id":143707871,"user":{"login":"TrevorPilley","id":1454073,"avatar_url":"https://avatars.githubusercontent.com/u/1454073?v=3","gravatar_id":"","url":"https://api.github.com/users/TrevorPilley","html_url":"https://github.com/TrevorPilley","followers_url":"https://api.github.com/users/TrevorPilley/followers","following_url":"https://api.github.com/users/TrevorPilley/following{/other_user}","gists_url":"https://api.github.com/users/TrevorPilley/gists{/gist_id}","starred_url":"https://api.github.com/users/TrevorPilley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TrevorPilley/subscriptions","organizations_url":"https://api.github.com/users/TrevorPilley/orgs","repos_url":"https://api.github.com/users/TrevorPilley/repos","events_url":"https://api.github.com/users/TrevorPilley/events{/privacy}","received_events_url":"https://api.github.com/users/TrevorPilley/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T10:50:07Z","updated_at":"2015-09-28T10:50:07Z","body":"OK lets pick the OData side of things up when we start making the ASP.NET vNext extension for MicroLite 7, in the interim, you could raise a separate issue to add support for mapping an entity to a Table-Valued Function if that is actually what you want?"}}