Skip to content
Draft
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
43 changes: 42 additions & 1 deletion docs/content/configuration and Input.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ SqlCommandProvider parameters
<tr><td class="title">AllParametersOptional</td><td>false</td><td>true/false</td></tr>
<tr><td class="title">ResolutionFolder</td><td>The folder that contains the project or script.</td><td>Valid file system path. Absolute or relative.</td></tr>
<tr><td class="title">DataDirectory</td><td>The name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.</td><td>Valid file system path.</td></tr>
<tr><td class="title">TempTableDefinitions</td><td>""</td><td>Semicolon-separated CREATE TABLE #Temp … statements. Allows queries that reference temporary tables.</td></tr>
<tr><td class="title">TableVarMapping</td><td>""</td><td>Maps inline table variables to existing user-defined table types, e.g. <code>@tvp1=dbo.MyTableType; @tvp2=dbo.OtherType</code>.</td></tr>
</tbody>
</table>

Expand Down Expand Up @@ -381,7 +383,46 @@ do
use cmd = new AdventureWorks2012.dbo.MyProc(connStr)
cmd.Execute([ T(myId = 2); T(myId = 1) ]) |> printfn "%A"

(**
(**
### Temp tables (`TempTableDefinitions`)

When a query references temporary tables (e.g. `#Temp`), the type provider needs to know their schema at
design time. Use `TempTableDefinitions` to supply the `CREATE TABLE #…` statement(s) (semicolon-separated).

At runtime, the generated `LoadTempTables` method must be called **before** `Execute` to populate the
temp tables. They are automatically dropped when the `SqlConnection` is closed or the command is disposed.
*)

// Declare a temp-table schema; the provider generates a LoadTempTables method and a nested record type.
type TempTableExample =
SqlCommandProvider<
CommandText = "SELECT Id, Name FROM #Items",
ConnectionStringOrName = connStr,
TempTableDefinitions = "CREATE TABLE #Items (Id INT NOT NULL, Name NVARCHAR(100) NULL)">

(**
Usage (connection must be open and passed to the command constructor):

use conn = new SqlConnection(connStr)
conn.Open()
use cmd = new TempTableExample(conn)
cmd.LoadTempTables(Items = [TempTableExample.Items(Id = 1, Name = Some "foo")])
cmd.Execute() |> Seq.iter ...

### Inline TVPs via `TableVarMapping`

Normally `SqlCommandProvider` discovers TVP types automatically when the query calls a stored procedure.
For **inline queries** that reference a table-valued parameter, the server cannot infer the user-defined
table type and the provider needs a hint.

Use `TableVarMapping` to map each table-variable parameter to its user-defined table type. The format is
a semicolon-separated list of `@param=schema.TypeName` pairs:

TableVarMapping = "@tvp1=dbo.MyTableType; @tvp2=dbo.OtherType"

Note: if you need to use the same parameter name more than once in an inline query, declare the type
explicitly in `TableVarMapping` — see the [FAQ](faq.html) for details.

### Stored procedures

Command types generated by `SqlProgrammabilityProvider<...>` largely have same interface with exceptions:
Expand Down
Loading