简体   繁体   English

为什么Dapper在构建命令时会删除任何参数前缀字符?

[英]Why does Dapper remove any parameter prefix characters when building a Command?

I am calling a stored procedure in Sybase ASE, using the "ASEOLEDB.1" provider. 我使用“ASEOLEDB.1”提供程序在Sybase ASE中调用存储过程。

The SP takes a single varchar(255) argument, called @PricePreference, which is defaulted to NULL in the SP. SP采用单个varchar(255)参数,称为@PricePreference,在SP中默认为NULL。

I am using Dapper's QueryMultiple method, and passing in a DynamicParameters object: 我正在使用Dapper的QueryMultiple方法,并传入DynamicParameters对象:

var parameters = new DynamicParameters();
parameters.Add("@PricePreference", "Foo");
var reader = dbConnection.QueryMultiple("myProcName", parameters, commandType: CommandType.StoredProcedure);

This code behaves as if I didn't pass the parameter at all. 此代码的行为就像我根本没有传递参数一样。 It appears this is because the AddParameters() method on Dapper's DynamicParameters class calls Clean() on my parameter name which removes the '@' prefix (or the equivalent for other DBMS' - see 'Working with Parameter Placeholders' on MSDN here ). 看来这是因为AddParameters()上小巧精致的DynamicParameters类的方法对我的参数名称其删除“@”前缀(或等值其他DBMS” -看‘与参数占位符MSDN上的工作’调用清理() 在这里 )。

Without the '@' prefix, Sybase appears unable to match up the argument. 如果没有'@'前缀,Sybase似乎无法匹配参数。

Conversely, when I comment out the call to Clean(), I get the correct result from the query. 相反,当我注释掉对Clean()的调用时,我从查询中得到了正确的结果。

What is the rationale behind removing the '@' prefix? 删除“@”前缀背后的理由是什么?

In short: it simplifies an awful lot of code and checks if we only need to worry about one scenario. 简而言之:如果我们只需要担心一个场景,它就会简化大量的代码并进行检查。 In every other RDBMS: it works equally fine with and without - and of course, when you specify parameter names via object properties they are: without - so it was the obvious way tobstandardise. 在所有其他RDBMS中:无论有没有它都可以正常工作 - 当然,当您通过对象属性指定参数名称时,它们是:没有 - 所以这是显而易见的方法。 If this doesn't work with a particular RDBMS, I'm sure we can investigate ways of fixing it. 如果这不适用于特定的RDBMS,我相信我们可以研究修复它的方法。 Presumably just by trusting DynamicParameters and not cleaning them. 大概只是信任DynamicParameters而不是清理它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM