Recursive Queries (F # 3.0)

I am trying to determine the type of Bill Of Materials queries using the recently introduced F # 3.0 query understanding syntax. Although such queries can be defined using yield!seq methods for in-memory collections, I haven’t lacked translating them into an understanding of queries intended for remote IQueryable sources. My guess is that the hard part will be to β€œtrain” the provider in recognizing common table expressions from recursive patterns.

Any ideas?

+3
source share
1 answer

, , F # 3.0 . , F # 3.0 IQueryable, #, .

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

, :

open System.IO
open Microsoft.FSharp.Quotations

type MyQueryBuilder() =
  member x.For(a, body) = Seq.collect body a
  member x.Quote(e) = e
  member x.YieldFrom(s) = s
  member x.Run(e:Expr<'T>) : 'T = failwithf "%A" e

// Example using the custom query builder
// (fails, printing the quoted query)
let mquery = MyQueryBuilder()    
let n = [1 .. 10]

let rec nums a : seq<int> =
  mquery { for b in n do
           yield! nums b }

Run , . MyQueryBuilder query - . query.Run ( IQueryable).

, , , , , , , - , , . , LINQ to SQL , , - , .

+5

All Articles