Skip to content

Commit 3a9a563

Browse files
github-actions[bot]Copilot
authored andcommitted
docs: document TempTableDefinitions and TableVarMapping parameters (#350)
Add the two missing SqlCommandProvider parameters to the configuration table and add new subsections explaining each feature with usage examples: - TempTableDefinitions: explains that the provider generates a LoadTempTables method and a nested record type for each temp table; shows the declare/populate/execute pattern. - TableVarMapping: explains when and why it is needed (inline TVP queries where sp_describe_undeclared_parameters cannot infer the UDT), gives the key=value format, and cross-references the FAQ for the duplicate- parameter limitation. Closes #350 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ad31241 commit 3a9a563

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

docs/content/configuration and Input.fsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SqlCommandProvider parameters
2020
<tr><td class="title">AllParametersOptional</td><td>false</td><td>true/false</td></tr>
2121
<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>
2222
<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>
23+
<tr><td class="title">TempTableDefinitions</td><td>""</td><td>Semicolon-separated CREATE TABLE #Temp … statements. Allows queries that reference temporary tables.</td></tr>
24+
<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>
2325
</tbody>
2426
</table>
2527
@@ -381,7 +383,46 @@ do
381383
use cmd = new AdventureWorks2012.dbo.MyProc(connStr)
382384
cmd.Execute([ T(myId = 2); T(myId = 1) ]) |> printfn "%A"
383385

384-
(**
386+
(**
387+
### Temp tables (`TempTableDefinitions`)
388+
389+
When a query references temporary tables (e.g. `#Temp`), the type provider needs to know their schema at
390+
design time. Use `TempTableDefinitions` to supply the `CREATE TABLE #…` statement(s) (semicolon-separated).
391+
392+
At runtime, the generated `LoadTempTables` method must be called **before** `Execute` to populate the
393+
temp tables. They are automatically dropped when the `SqlConnection` is closed or the command is disposed.
394+
*)
395+
396+
// Declare a temp-table schema; the provider generates a LoadTempTables method and a nested record type.
397+
type TempTableExample =
398+
SqlCommandProvider<
399+
CommandText = "SELECT Id, Name FROM #Items",
400+
ConnectionStringOrName = connStr,
401+
TempTableDefinitions = "CREATE TABLE #Items (Id INT NOT NULL, Name NVARCHAR(100) NULL)">
402+
403+
(**
404+
Usage (connection must be open and passed to the command constructor):
405+
406+
use conn = new SqlConnection(connStr)
407+
conn.Open()
408+
use cmd = new TempTableExample(conn)
409+
cmd.LoadTempTables(Items = [TempTableExample.Items(Id = 1, Name = Some "foo")])
410+
cmd.Execute() |> Seq.iter ...
411+
412+
### Inline TVPs via `TableVarMapping`
413+
414+
Normally `SqlCommandProvider` discovers TVP types automatically when the query calls a stored procedure.
415+
For **inline queries** that reference a table-valued parameter, the server cannot infer the user-defined
416+
table type and the provider needs a hint.
417+
418+
Use `TableVarMapping` to map each table-variable parameter to its user-defined table type. The format is
419+
a semicolon-separated list of `@param=schema.TypeName` pairs:
420+
421+
TableVarMapping = "@tvp1=dbo.MyTableType; @tvp2=dbo.OtherType"
422+
423+
Note: if you need to use the same parameter name more than once in an inline query, declare the type
424+
explicitly in `TableVarMapping` — see the [FAQ](faq.html) for details.
425+
385426
### Stored procedures
386427
387428
Command types generated by `SqlProgrammabilityProvider<...>` largely have same interface with exceptions:

0 commit comments

Comments
 (0)