我正在尝试通过以下简单查询使用 Dapper orm:
var sqlString = new StringBuilder();
sqlString.Append("select a.acct AccountNumber,");
sqlString.Append(" b.first_name FirstName,");
sqlString.Append(" b.last_name LastName,");
sqlString.Append(" a.rr RrNumber,");
sqlString.Append(" c.addr1 AddressLine1,");
sqlString.Append(" c.addr2 AddressLine2,");
sqlString.Append(" c.addr3 AddressLine3,");
sqlString.Append(" c.addr4 AddressLine4,");
sqlString.Append(" c.addr5 AddressLine5,");
sqlString.Append(" c.addr6 AddressLine6,");
sqlString.Append(" c.addr7 AddressLine7,");
sqlString.Append(" c.addr8 AddressLine8 ");
sqlString.Append("from (pub.mfclac as a left join pub.mfcl as b on a.client=b.client) ");
sqlString.Append("left join pub.mfclad as c on a.client=c.client ");
sqlString.Append("where a.acct = '@ZYX'");
var connection = new OdbcConnection(_connectionString);
var result = connection.Query(sqlString.ToString(),
new
{
ZYX = accountNumber
});
但是,当我使用已知存在的 accountNumber 执行此操作时,dapper 什么也不返回。因此,我尝试删除引号以验证该参数实际上是否已替换为帐号,但是从服务器返回的错误表明“@ZYX”周围存在语法错误。这意味着 dapper 不会用给定的值替换参数。任何想法为什么会发生这种情况?从那里有限的文档来看,这应该“正常工作”。
编辑1
无法让它工作。使用 string.format 插入参数作为解决方法。