7

I'm learning F# and playing around with type providers and I've connected the awesome FSharp.Data.SQLProvider to a SQL Server instance. I'm able to use F#'s query expression syntax to perform queries against the database but I'd like to see the SQL that is generated by the type provider. I've tried to assign Console.Out to what I assume is the DataContext but I get an error saying

Error FS0810: Property 'Log' cannot be set

How do I log the SQL generated by the type provider?

#r @"packages/SQLProvider/lib/FSharp.Data.SqlProvider.dll"
#r @"System.Data.Linq.dll"
open System
open System.Data.Linq
open FSharp.Data.Sql
[<Literal>]
let connectionString = @"SuperSecretString"
type Sql = SqlDataProvider<
 ConnectionString = connectionString,
 DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER,
 IndividualsAmount = 1000>
let ctx = Sql.GetDataContext()
ctx.Log <- Console.Out // error FS0810: Property 'Log' cannot be set
marc_s
759k184 gold badges1.4k silver badges1.5k bronze badges
asked Aug 26, 2016 at 20:18

1 Answer 1

6

You can listen to the event SqlQueryEvent:

FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O")
answered Aug 31, 2016 at 16:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.