ExecuteReader 不支持 MultiExec
MultiExec is not supported by ExecuteReader
我有以下代码:
let getByIdAsync (connectionString : string) (id : int) =
let sql = @"SELECT * FROM [User] WHERE [Id] = @id"
let args = [ "id" => id ]
async {
use connection = new SqlConnection(connectionString)
do! connection.OpenAsync() |> Async.AwaitTask
try
use! reader = connection.ExecuteReaderAsync(sql, args) |> Async.AwaitTask
return reader |> mapRowsToRecords |> Seq.head
with
| e -> return Error e.Message
}
此代码抛出 MultiExec is not supported by ExecuteReader
,我不知道为什么。其他查询(例如我的插入)工作正常。我做错了什么?
我知道哪里不对了,字典前少了dict
:
let getByIdAsync (connectionString : string) (id : int) =
let sql = @"SELECT * FROM [User] WHERE [Id] = @id"
let args = dict [ "id" => id ] // added dict
async {
use connection = new SqlConnection(connectionString)
do! connection.OpenAsync() |> Async.AwaitTask
try
use! reader = connection.ExecuteReaderAsync(sql, args) |> Async.AwaitTask
return reader |> mapRowsToRecords |> Seq.head
with
| e -> return Error e.Message
}
查看 this article 了解更多信息。
我有以下代码:
let getByIdAsync (connectionString : string) (id : int) =
let sql = @"SELECT * FROM [User] WHERE [Id] = @id"
let args = [ "id" => id ]
async {
use connection = new SqlConnection(connectionString)
do! connection.OpenAsync() |> Async.AwaitTask
try
use! reader = connection.ExecuteReaderAsync(sql, args) |> Async.AwaitTask
return reader |> mapRowsToRecords |> Seq.head
with
| e -> return Error e.Message
}
此代码抛出 MultiExec is not supported by ExecuteReader
,我不知道为什么。其他查询(例如我的插入)工作正常。我做错了什么?
我知道哪里不对了,字典前少了dict
:
let getByIdAsync (connectionString : string) (id : int) =
let sql = @"SELECT * FROM [User] WHERE [Id] = @id"
let args = dict [ "id" => id ] // added dict
async {
use connection = new SqlConnection(connectionString)
do! connection.OpenAsync() |> Async.AwaitTask
try
use! reader = connection.ExecuteReaderAsync(sql, args) |> Async.AwaitTask
return reader |> mapRowsToRecords |> Seq.head
with
| e -> return Error e.Message
}
查看 this article 了解更多信息。