为什么 SQL Anywhere 会忽略 @ 命名参数?

Why does SQL Anywhere ignore the @ named parameter?

我正在使用 Dapper 查询 SQL Anywhere 数据源,我收到一个错误,似乎我的 where 子句值的“@”前缀被忽略了。

 Double balance = qb.Query<Double>("select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = @listid", new { listid = ListID }).Single();

错误:

Column '@listid' not found

我可以访问那个 table 并且我的手动查询工作正常。

select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = '8000000B-1433635931'

示例:

帮我看看您是否尝试使用未声明的变量@listid。

如果我在任何地方使用 DBISQL 和 SQL 我会写这样的东西:

开始

声明@list varchar(20);

SET @list = '8000000B-1433635931';

select end_balance_amt 来自 QBReportAdminGroup.v_lst_customer 其中 list_ident = @listid";

结束

使用 SQL Anywhere 及其 .Net 数据提供程序(至少 Sap.Data.SQLAnywherev4.5),参数应以 : 为前缀,而不是 @.

在我看来,这就是您遇到的问题。但我不知道 Dapper 是否应该从其用户那里抽象出此类供应商的特定行为。

所以你应该试试:

Double balance = qb.Query<Double>(
    "select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = :listid",
    new { listid = ListID }).Single();