2017-03-08 74 views
1

执行MySQL存储过程什么是使用Database.ExecuteSqlCommand与MySQL的参数的正确语法?

var affectedRows = 
     context.Database.ExecuteSqlCommand("exec UpdateStatus @p_customerId, @p_id", 
      new MySqlParameter("p_customerId", "006"), 
      new MySqlParameter("p_id", 9)); 

获取个MySqlException

型 'MySql.Data.MySqlClient.MySqlException' 未处理的异常发生在EntityFramework.dll

更多信息:您有一个您的SQL语法错误;检查 对应于您的MySQL服务器版本的权利 语法手册使用近“EXEC UpdateStatus ‘006’,9”位于第1行

当我试着使用一个更新语句来代替存储过程的名称有用。但我想调用一个存储过程。

我试图使用实体框架5和6相同的错误

回答

1

MySQL的语法的命令从调用存储过程是“CALL”。参数名称前面应该有“@”。

所以,你需要更改代码如下。

var affectedRows = 
    context.Database.ExecuteSqlCommand("CALL UpdateStatus (@p_customerId, @p_id)", 
     new MySqlParameter("@p_customerId", "006"), 
     new MySqlParameter("@p_id", 9)); 
+0

非常感谢你!!!! – Ben

相关问题