如何将参数传递给FsSql中的Sql.execReaderF?

时间:2015-10-15 11:57:44

标签: f# f#-data

我正在尝试FsSql的示例,我似乎陷入了如何正确使用Sql.execReaderF函数。示例代码使用int参数,但我有一个字符串。以下代码块显示了我的尝试。 FsSql是否仅支持此函数的int?

设置代码:

module FsSqlTests

open System
open System.Data
open System.Data.SqlClient
open NUnit.Framework
open Swensen.Unquote

let openConn() =
        let conn = new SqlConnection(@"Data Source=MYSERVER;Initial Catalog=MYDB;Integrated Security=True")
        conn.Open()
        conn :> IDbConnection

let connMgr = Sql.withNewConnection openConn 

let P = Sql.Parameter.make

let execReader sql = Sql.execReader connMgr sql 

let execReaderf sql = Sql.execReaderF connMgr sql

使用Sql.execReader(使用此测试用例传递)

let selectSummaryByeFolderName eFolderName = 
    execReader "select summary from ework.V_DQ_Iccm_Activity_By_Team WHERE efoldername = @eFolderName"
        [P("@eFolderName", eFolderName)]

使用Sql.execReaderF(使用此测试用例失败)

let selectSummaryByeFolderName = 
    execReaderf "select summary from ework.V_DQ_Iccm_Activity_By_Team WHERE efoldername = '%s'"

在测试用例中调用代码:

[<TestCase>]
let ``Gets CM summary given eFolderName``() =
    let c = selectSummaryByeFolderName "CM008671"

    let r = c
            |> Seq.ofDataReader
            |> Seq.map(fun dr ->
                let s = 
                    match dr?summary with
                    | None -> "No Summary"
                    | Some x -> x
                s)
            |> Seq.length

    test <@ r > 0 @>

如何修改对execReaderF的调用以使其通过参数并正确运行?

更新: 我用一个整数参数尝试了它,它工作正常。似乎该函数可能只支持整数。

let selectSummaryByCallPriority = 
    execReaderf "select top 10 summary from ework.V_DQ_Iccm_Activity_By_Team WHERE callpriority = %d"

我查看了实现以尝试验证这一点,但它已经超出了我的想象。无论如何,Sql.execReader函数适用于其他数据类型,所以我可以切换到我的字符串参数的函数。

0 个答案:

没有答案