Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/SqlClient.DesignTime/DesignTime.fs
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,9 @@ type DesignTime private() =
<@@ let cmd = (%%command : ISqlCommand)
cmd.Raw.Connection @@>

<@@ do
use create = (%%connection : SqlConnection).CreateCommand(CommandText = tempTableDefinitions)
create.ExecuteNonQuery() |> ignore

<@@ use openedConn = (%%connection : SqlConnection).UseLocally()
use create = (%%connection : SqlConnection).CreateCommand(CommandText = tempTableDefinitions)
create.ExecuteNonQuery() |> ignore
(%%loadValues exprArgs connection)
ignore() @@>)

Expand Down
22 changes: 22 additions & 0 deletions tests/SqlClient.Tests/TempTableTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ type TempTable =
ConnectionStringOrName =
ConnectionStrings.AdventureWorksLiteral>

[<Fact>]
let usingTempTableWithConnectionString() =
// Regression test for issue #306: LoadTempTables should auto-open the connection
use cmd = new TempTable(ConnectionStrings.AdventureWorksLiteral)

cmd.LoadTempTables(
Temp =
[ TempTable.Temp(Id = 1, Name = Some "cat")
TempTable.Temp(Id = 2, Name = Some "dog") ])

let actual =
cmd.Execute()
|> Seq.map(fun x -> x.Id, x.Name)
|> Seq.toList

let expected = [
1, Some "cat"
2, Some "dog"
]

Assert.Equal<_ list>(expected, actual)

[<Fact>]
let usingTempTable() =
use conn = new SqlConnection(ConnectionStrings.AdventureWorksLiteral)
Expand Down
Loading