I'm using Entity Framework in an ASP.NET MVC3 application and I'm trying to use the following code:
var token = ""; this.Database.ExecuteSqlCommand("exec dbo.MyUsp", new SqlParameter("token", token));   My stored proc signature is:
CREATE PROCEDURE MyUSP(@token varchar(10) OUT) (...)   When I use this code I get an error saying that parameter "@token" was expected but not supplied.
How do I tell EF that the token parameter is for output?
You can execute SP using FromSql method in EF Core in the same way as above, as shown below.
I ended up using this to get it working, but I'm sure there's a more optimal way:
var p = new SqlParameter {     ParameterName = "token",     DbType = System.Data.DbType.String,     Size = 100,     Direction = System.Data.ParameterDirection.Output }; var resp = this.Database.SqlQuery<String>("exec dbo.usp_GetRequestToken @token", p);  return resp.First(); 
                        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