You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using an object as parameters template, and use the DynamicParameters.Add method to 'override' a string property to DbString so that it can use SQL Server index.
But i got the exception : The variable name has already been declared.
publicstaticvoidRun(){Test(1);//okTest("1");//okTest(DateTime.Now);//okTest(newDbString(){Value="1"});//System.Data.SqlClient.SqlException: 'The variable name '@Value' has already been declared.}publicstaticvoidTest<T>(Tvalue){using(SqlConnectionconn=newSqlConnection("Data Source=.;Initial Catalog=master;Persist Security Info=True;")){vartemplate=new{Value=value};vardp=newDynamicParameters(template);dp.Add("Value",value);conn.Execute("SELECT 1 WHERE @Value IS NOT NULL",dp);}}
The text was updated successfully, but these errors were encountered:
Not only DbString, any type implement SqlMapper.ICustomQueryParameter have this issue.
For other types(does not ICustomQueryParameter), there are some code to prevent dupilcate parameters, so there are no problem. DynamicParameters.AddParameters code:
if(isCustomQueryParameter){// DbString goes to here.}else{booladd=!command.Parameters.Contains(name);IDbDataParameterp;if(add){p=command.CreateParameter();p.ParameterName=name;}else{p=(IDbDataParameter)command.Parameters[name];}}
so ICustomQueryParameter will be appended to command twice:
I am using an object as parameters template, and use the DynamicParameters.Add method to 'override' a string property to DbString so that it can use SQL Server index.
But i got the exception : The variable name has already been declared.
The text was updated successfully, but these errors were encountered: