Composing many quotes in linq queries

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) @>

..

?

+3
1

, .

, F # LINQ . , , , , , , .

, - ( , , , ):

let (|>*) f g = fun c -> <@ (%c) |> (%f) |> (%g) @> 

<@ seq { for prod in (%dc).Products do 
           if (%predicates) prod then yield prod } @> |>
( <@ Seq.sortBy (fun prod -> prod.Name) @> |>*
  <@ Seq.sortBy (fun prod -> prod.Style) @> )

, - , F # - , ( LINQ to SQL ). ...

F # . , fsbugs microsoft dot com. PowerPack "", , ( promises).

+1

Source: https://habr.com/ru/post/1791299/


All Articles