EF6使用参数调用存储过程

时间:2015-06-17 11:35:58

标签: c# mysql entity-framework-6 edmx

我在MySQL中有一个存储过程,它接受一个整数并返回多个结果集 据我了解,我认为这是一种方法。

var cmd = context.Database.Connection.CreateCommand();
cmd.CommandText = "CALL `GetBlogPosts`(@BlogId)";
cmd.Parameters.Add(new MySqlParameter { ParameterName = "BlogId", Value = 1 });

但是我得到了这个错误:

The specified cast from a materialized 'System.String' type to the 'System.Int32' type is not valid.

如果我将命令改为此

cmd.CommandText = "CALL `GetBlogPosts`({@BlogId})";

我收到此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1})' at line 1

0 个答案:

没有答案