Skip to content

Commit

Permalink
add "ExecuteQuery" sample with anonymous records
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelMunoz committed Sep 3, 2020
1 parent b9b07f2 commit a50fcdd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion FSharp/FSharpRepoDB/FSharpRepoDB/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let main argv =
Console.WriteLine("Insert<TEntity>: Generated Id = {0}", Convert.ToString(id))

// Insert(TableName)
let person = {| Name = "James Smith"; Age = 32; Address = "Washington"; IsActive = true|}
let person = {| Name = "James Smith"; Age = 32; Address = "Washington"; IsActive = false|}
let id = connection.Insert<int64>(ClassMappedNameCache.Get<Person>(), person)
Console.WriteLine("Insert(TableName): Generated Id = {0}", Convert.ToString(id))

Expand All @@ -59,6 +59,14 @@ let main argv =
let result = connection.QueryAll(ClassMappedNameCache.Get<Person>()).AsList()
Console.WriteLine("QueryAll(TableName): Count = {0}", result.Count)

// Query with anonymous records, pull only what you need
let result =
connection.ExecuteQuery<{| Name: string; Age: int |}>(
@"SELECT Name, Age FROM [dbo].[Person] WHERE IsActive = @isactive",
dict(["@isactive", box false ])
).AsList()
printfn "ExecuteQuery(SQL query): Count = %i\n\tFirst Value =\n\t'%A'" result.Count (result |> Seq.tryHead)

// Dispose the connection
connection.Dispose()

Expand Down

0 comments on commit a50fcdd

Please sign in to comment.