Skip to content

Commit a50fcdd

Browse files
committed
add "ExecuteQuery" sample with anonymous records
1 parent b9b07f2 commit a50fcdd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

FSharp/FSharpRepoDB/FSharpRepoDB/Program.fs

+9-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let main argv =
4747
Console.WriteLine("Insert<TEntity>: Generated Id = {0}", Convert.ToString(id))
4848

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

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

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

0 commit comments

Comments
 (0)