EF6 Call stored procedure with parameters

178 views Asked by At

I have a stored procedure in MySQL that accepts an integer and returns multiple resultsets.
From what I understand, I see this is one way to do it.

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

But am get this error:

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

If I change the command to this

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

I am getting this error:

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

There are 0 answers