gpt4 book ai didi

c# - Dapper 参数替换不适用于 Top

转载 作者:IT王子 更新时间:2023-10-29 04:42:38 26 4
gpt4 key购买 nike

这是我的sql

var maxLimit =100;
var sql = "Select Top @MaxLimit from Table WHere data =@Id"
conn.Query<Result>(sql, new {
Id = customerId,
MaxLimit = maxLimit
})

但是我得到一个系统错误

incorrect syntax near @MaxLimit.

Dapper 是否无法参数化 Top 或 Fetch 等字段?

最佳答案

在 SQL Server 中,除数字常量之外的任何 top 表达式都需要放在括号中。

SELECT TOP (@MaxLimit) FROM ...

关于c# - Dapper 参数替换不适用于 Top,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36946879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com