This is code cut right from the Dapper examples:
var p = new DynamicParameters();
p.Add("@a", 11);
p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
cnn.Execute("spMagicProc", p, commandType: commandType.StoredProcedure);
int b = p.Get("@b");
int c = p.Get("@c");
Anyone: In the above code from the example provided, I get an error, "can't resolve .Execute"--referring to cnn.Execute
. I look at the connection object and there is no method for Execute. Dapper obviously works well, so what am I doing wrong?
I believe this should get you fixed up:
using( var connection = new SqlConnection( connectionString ) )
{
try
{
var p = new DynamicParameters();
p.Add( "a", 11 );
p.Add( "b", dbType: DbType.Int32, direction: ParameterDirection.Output );
p.Add( "c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue );
connection.Open();
connection.Execute( "MyDamnStoredProc", p, commandType: CommandType.StoredProcedure );
int b = p.Get<int>( "b" );
int c = p.Get<int>( "c" );
}
catch( Exception ex )
{
Console.WriteLine( ex.Message );
}
}
Notes:
commandType:
parameter. You do this so the optional parameters can be omitted from the method call."can't resolve .Execute"
That would be cause your extension method is missing, did you using Dapper;
at the top of your file.
See also: http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With