Skip to content

Instantly share code, notes, and snippets.

@dmitry-a-morozov
Created August 29, 2013 15:36
Show Gist options
  • Save dmitry-a-morozov/6379684 to your computer and use it in GitHub Desktop.
Save dmitry-a-morozov/6379684 to your computer and use it in GitHub Desktop.
SqlCommandTypeProvider usage example.
#r "bin/Debug/SqlCommandTypeProvider.dll"
open FSharp.NYC.Tutorial
[<Literal>]
let connectionString="Data Source=.\SQLExpress;Initial Catalog=AdventureWorks2012;Integrated Security=True"
type QueryPersonInfo = SqlCommand<"SELECT * FROM dbo.ufnGetContactInformation(@PersonId)", connectionString>
let query = new QueryPersonInfo(PersonId = 2)
query.Execute()
|> Async.RunSynchronously
|> Seq.toArray
|> Array.iter (fun x ->
printfn "Person info: Id - %i, FirstName - %s, LastName - %s, JobTitle - %s, BusinessEntityType - %s" x.PersonID x.FirstName x.LastName x.JobTitle x.BusinessEntityType
)
type UpdateEmplInfoCommand = SqlCommand<"EXEC HumanResources.uspUpdateEmployeePersonalInfo @BusinessEntityID, @NationalIDNumber, @BirthDate, @MaritalStatus, @Gender", connectionString>
let cmd = new UpdateEmplInfoCommand(BusinessEntityID = 2, NationalIDNumber = "245797967", BirthDate = System.DateTime(1965, 09, 01), MaritalStatus = "S", Gender = "F")
cmd.Execute() |> Async.RunSynchronously
type GetServerTime = SqlCommand<"IF @IsUtc = CAST(1 AS BIT) SELECT GETUTCDATE() AS Now ELSE SELECT GETDATE() AS Now", connectionString>
let getSrvTime = new GetServerTime(IsUtc = true)
getSrvTime.Execute() |> Async.RunSynchronously |> Seq.map (fun x -> x.Now) |> Seq.exactlyOne |> printfn "%A"
getSrvTime.IsUtc <- false
getSrvTime.Execute() |> Async.RunSynchronously |> Seq.map (fun x -> x.Now) |> Seq.exactlyOne |> printfn "%A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment