{"action":"created","issue":{"url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/177","labels_url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/177/labels{/name}","comments_url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/177/comments","events_url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/177/events","html_url":"https://github.com/fsprojects/SQLProvider/issues/177","id":119252385,"number":177,"title":"Calling functions in query?","user":{"login":"Thorium","id":229355,"avatar_url":"https://avatars.githubusercontent.com/u/229355?v=3","gravatar_id":"","url":"https://api.github.com/users/Thorium","html_url":"https://github.com/Thorium","followers_url":"https://api.github.com/users/Thorium/followers","following_url":"https://api.github.com/users/Thorium/following{/other_user}","gists_url":"https://api.github.com/users/Thorium/gists{/gist_id}","starred_url":"https://api.github.com/users/Thorium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Thorium/subscriptions","organizations_url":"https://api.github.com/users/Thorium/orgs","repos_url":"https://api.github.com/users/Thorium/repos","events_url":"https://api.github.com/users/Thorium/events{/privacy}","received_events_url":"https://api.github.com/users/Thorium/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-27T21:57:25Z","updated_at":"2015-11-27T22:05:15Z","closed_at":null,"body":"This is just a random thought...\r\n\r\n- We have a [way] (http://www.fssnip.net/ts) to convert F# quotations to C# `Expression<Func<_>>`\r\n- We have a [tool] (https://github.com/scottksmith95/LINQKit) to convert `Expression<Func<_>>` to `IQueryable<_>` from outside of DBContext. This tool is using Tomas P's old [idea](http://tomasp.net/blog/linq-expand.aspx/).\r\n- SQLProvider executes F# query (as `IQueryable<_>`) via SQLMetal to databases\r\n\r\nThis should mean that we could quite easily combine these tools to convert F# lambda functions to SQL queries also from outside of database context `query { ... }`. Right?\r\n\r\nWith that you could do things like this (maybe with better syntax):\r\n\r\n    let commonFilter = \r\n        <@ Func<_, _>(fun c ->  c.ContactName = \"Matti\") @> |> Lambda.toExpression\r\n\r\n    let matti =\r\n        query { for c in ctx.``[main].[Customers]``.AsExpandable() do\r\n                where (commonFilter.Invoke c)\r\n                head\r\n        } |> Seq.toArray\r\n\r\n...and the commonFilter is actually translated into SQL-clause.\r\n\r\n- Would this be usefull or not? \r\n- Could this be used to support advanced SQL-queries without implementing the whole F# Query Expressions interface?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/comments/160218513","html_url":"https://github.com/fsprojects/SQLProvider/issues/177#issuecomment-160218513","issue_url":"https://api.github.com/repos/fsprojects/SQLProvider/issues/177","id":160218513,"user":{"login":"pezipink","id":2384821,"avatar_url":"https://avatars.githubusercontent.com/u/2384821?v=3","gravatar_id":"","url":"https://api.github.com/users/pezipink","html_url":"https://github.com/pezipink","followers_url":"https://api.github.com/users/pezipink/followers","following_url":"https://api.github.com/users/pezipink/following{/other_user}","gists_url":"https://api.github.com/users/pezipink/gists{/gist_id}","starred_url":"https://api.github.com/users/pezipink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pezipink/subscriptions","organizations_url":"https://api.github.com/users/pezipink/orgs","repos_url":"https://api.github.com/users/pezipink/repos","events_url":"https://api.github.com/users/pezipink/events{/privacy}","received_events_url":"https://api.github.com/users/pezipink/received_events","type":"User","site_admin":false},"created_at":"2015-11-27T22:05:15Z","updated_at":"2015-11-27T22:05:15Z","body":"Firstly SQLProvider does NOT use SQLMetal, that is the whole point of it. SQLMetal generates tons of code behind the scenes and only supports SQL Server.  If we were using SQLMetal would not have to implement an entire LINQ expression compiler like we currently are (which is why we don't support stuff like aggregation and nested queries, as we have not done it yet).\r\n\r\nThat aside, you may well be able to use some of this stuff to generate your IQueryable trees, as long as they are in a format which our compiler can deal with, however, most of the stuff you are looking at here can be achieved with the F# composable query project, it mostly worked with the SQLProvider anyways and @colinbull did a good bit of work to increase support for it (I think!) \r\n\r\nhttp://fsprojects.github.io/FSharp.Linq.ComposableQuery/\r\n\r\nCheers"}}