如何在fsharp.data.sqlclient中使用SQL IN语句? [英] How to use SQL IN statement in fsharp.data.sqlclient?

查看:95
本文介绍了如何在fsharp.data.sqlclient中使用SQL IN语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例代码.目的是使用多个输入参数运行SQL语句.

I have the following sample code. The objective is to run SQL statement with multiple input parameters.

[<Literal>]
let connectionString = @"Data Source=Localhost;Initial Catalog=Instrument;Integrated Security=True"
[<Literal>]
let query = "SELECT MacroName, MacroCode FROM Instrument WHERE MacroCode IN (@codeName)"

type MacroQuery = SqlCommandProvider<query, connectionString>
let cmd = new MacroQuery()
let res = cmd.AsyncExecute(codeName= [|"CPI";"GDP"|]) |> Async.RunSynchronously

但是,推断codeName是字符串类型而不是数组或列表,这会给我一个错误.

However, codeName is inferred to be string type instead of an array or list and give me an error.

或者,我可以在没有where语句的情况下运行查询,并根据结果进行过滤.但是,在许多其他情况下,它们返回数百万行,我更希望在SQL Server级别过滤数据以提高效率.

Alternatively, I could run the query without where statement and filter based on the result. However, in lots of other cases that returns millions of rows, I would prefer filter data at the SQL server level to be more efficient.

在fsharp.data.sqlclient的文档中找不到任何相关示例.请帮忙!

I didn't find any relevant samples on the documentation of fsharp.data.sqlclient. Please help!

推荐答案

查看文档中的表值参数(TVP)"部分: http://fsprojects.github.io/FSharp.Data.SqlClient /configuration%20and%20input.html

"See Table-valued parameters (TVPs)" section in the documentation: http://fsprojects.github.io/FSharp.Data.SqlClient/configuration%20and%20input.html

这篇关于如何在fsharp.data.sqlclient中使用SQL IN语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆