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
You can listen to the event SqlQueryEvent:
FSharp.Data.Sql.Common.QueryEvents.SqlQueryEvent |> Event.add (printfn "Executing SQL: %O")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With