.netado.netdappersqlanywhere

Why does SQL Anywhere ignore the @ named parameter?


I am using Dapper to query a SQL Anywhere Datasource, and I am getting an error that makes it seem that the "@" prefix for my where clause value is ignored.

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

Error:

Column '@listid' not found

I have access to that table and my manual query works fine.

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

Example:

enter image description here


Solution

  • With SQL Anywhere and its .Net data provider (at least Sap.Data.SQLAnywherev4.5), parameters should be prefixed with : instead of @.

    This looks to me as being the issue in your case. But I do not know if Dapper is supposed to abstract away such vendor's specific behavior from its users.

    So you should try with:

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