我正在使用 FSharp.Data.SqlClient 类型提供程序,并且在访问具有表值参数的存储过程时不断收到错误。
我逐字尝试了文档中的示例
CREATE TYPE myTableType AS TABLE (myId int not null, myName nvarchar(30) null)
GO
CREATE PROCEDURE myProc
@p1 myTableType readonly
AS
BEGIN
SELECT myName from @p1 p
END
这应该允许我写以下内容
type myType = AdventureWorks2012.``User-Defined Table Types``.MyTableType
但它没有返回用户定义的表类型
下的任何选项
这使我无法调用任何采用表值参数的存储过程。
我正在运行类型提供程序的 Microsoft SQL Server Express(64 位)版本 12.0.2000.8 和版本 1.6.2(当前最新)
最佳答案
这对我有用(可能文档尚未更新):
[<Literal>]
let connectionString = @"... My connection string here..."
type TableValuedSample = SqlProgrammabilityProvider<connectionString>
type myType = TableValuedSample.dbo.``User-Defined Table Types``.myTableType
let m = [
myType(myId = 2, myName = "Mike")
myType(myId = 1, myName = "Pete")
]
let myArray =
(new TableValuedSample.dbo.myProc()).AsyncExecute(m) // syntax difference
|> Async.RunSynchronously
|> Array.ofSeq
let myRes = myArray.[0]
match myRes with
| Some res -> res
| None -> ""
结果:
>
val myArray : Option<string> [] = [|Some "Mike"; Some "Pete"|]
val myRes : Option<string> = Some "Mike"
val it : string = "Mike"
我正在使用 MSSQL 2014 和 1.6.2 提供程序。
关于f# - 具有用户定义表类型的 FSharp.Data.SqlClient 类型提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30263690/