diff --git a/docs/content/configuration and Input.fsx b/docs/content/configuration and Input.fsx index e621636a..f2c98f56 100644 --- a/docs/content/configuration and Input.fsx +++ b/docs/content/configuration and Input.fsx @@ -20,6 +20,8 @@ SqlCommandProvider parameters AllParametersOptionalfalsetrue/false ResolutionFolderThe folder that contains the project or script.Valid file system path. Absolute or relative. DataDirectoryThe name of the data directory that replaces |DataDirectory| in connection strings. The default value is the project or script directory.Valid file system path. + TempTableDefinitions""Semicolon-separated CREATE TABLE #Temp … statements. Allows queries that reference temporary tables. + TableVarMapping""Maps inline table variables to existing user-defined table types, e.g. @tvp1=dbo.MyTableType; @tvp2=dbo.OtherType. @@ -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: