Writing F# queries in LINQPad

You just need to add "this." in front of the mapped table if you want to run it as a F# Expression in LINQPad.

query { for c in this.Categories do
        select c }

Out of curiosity I decided to try and get something working with F# in LinqPad. I was able to get it working by selecting "F# Program" instead of F# expression. I'm sure it's possible using just an expression, but I am 100% unfamiliar with F# so I just did enough to get a working example. Selecting this option gave me a single line of:

let dc = new TypedDataContext()

From there, I followed this example page to get this query working/executing:

let dc = new TypedDataContext()

let query1 = query { for c in dc.MyTable do
                     select c }

query1
|> Seq.iter (fun x -> printfn "SomeField: %s" x.SomeField)

Tags:

C#

Linq

F#

Linqpad