I am working on a project in which I am trying to use F # and Linq for UDF and storing procs on a SQL server. Part of this is the static definition of all valid queries, sorting criteria, and a means of calculating query results.
I have been pretty successful so far, but I'm having serious difficulties compiling sortBy expressions.
Here is 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 @>
Ultimately, this will be used later in the query executor like this:
let execQuery = fun (predicates,sorts,scorer) ->
<@ seq { for prod in (%dc).Products do
if (%predicates) prod then yield prod }
|> (%sorts)
|> (%scorer) @>
Using these basic paths, everything works until I use (% sorts). Every time I skip this, I do not recognize the Linq translator in F #. I tried several different attempts to use combinators, but it makes sense that I am missing something. If I turn off the sort function with the following
<@ Seq.sortBy (fun prod -> prod.Name) |> Seq.sortBy (fun prod -> prod.Style) @>
, . , , :
let (|>*) = fun f g -> <@ fun c -> ((%f) c) |> (%g) @>
..
?