C# 使用dapper,在mysql调用存储过程时,提示在数据库中找不到存储过程或函数
一、创建存储过程
Delimiter $$
drop PROCEDURE if EXISTS pro_test;
create PROCEDURE pro_test(in idIn int)
begin
select count(1) as Count from tch_teacher where id > idIn;
end $$
Delimiter ;
Delimiter $$
drop PROCEDURE if EXISTS pro_test1;
create PROCEDURE pro_test1(in idIn int, out count int)
begin
select count(1) into count from tch_teacher where id > idIn;
select * from tch_teacher where id > idIn;
end $$
Delimiter ;
call pro_test(11);
set @count =0;
call pro_test1(11, @count);
select @count;
二、调用
//方法一
sql = "call pro_test(@id);";
var res = conn.Query<int>(sql, new { id = 15 }).FirstOrDefault(); //85
Console.WriteLine("res = " + res); //res = 85
//方法二
var param = new DynamicParameters();
param.Add("@idIn", 20);
param.Add("@count", 0, DbType.Int32, ParameterDirection.Output);
var res2 = conn.Query<Tch_Teacher>("pro_test1", param, null, true, null, CommandType.StoredProcedure);//res2.Count = 80
Console.WriteLine("Query count = " + param.Get<object>("@count")); //Query count = 80