composing many quotations into linq queries
-
12-11-2019 - |
Question
I'm working on a project in which I'm trying to use F# and Linq for UDF's and stored procs in an SQL server. Part of that has been to statically define all the valid queries, the sorting criteria, and a means of scoring the results of the queries.
I've so far been fairly successful, but I'm running into serious difficulty composing sortBy expressions.
Here's the basic concept
let sorter =
let exprMap:Map<string,Quotations.Expr<seq<Product> -> seq<Product>>> =
Map.ofList
["ProductName",<@ Seq.sortBy (fun prod -> prod.Name) @> ]
// .. more entries ..
let sortBuilder sortkeys =
Array.foldBack
(fun criteria acc -> <@ %(exprMap.[criteria]) >> (%acc) @>)
sortkeys
<@ Seq.map id @>
This ends up being used later in the query executor like so
let execQuery = fun (predicates,sorts,scorer) ->
<@ seq { for prod in (%dc).Products do
if (%predicates) prod then yield prod }
|> (%sorts)
|> (%scorer) @>
Using these basic outlines, everything works as long as I don't use (%sorts). Each time I pass that in, I get not recognized in F# to Linq translator. I've tried a number of different attempts at using combinators, but I have the sense I'm missing something. If I stub out the sorter function with the following
<@ Seq.sortBy (fun prod -> prod.Name) |> Seq.sortBy (fun prod -> prod.Style) @>
It works as expected. However using a combinator like this:
let (|>*) = fun f g -> <@ fun c -> ((%f) c) |> (%g) @>
does not..
Any ideas?
No correct solution