I have a stored procedure that has three parameters and I\'ve been trying to use the following to return the results:
context.Database.SqlQuery
Most answers are brittle because they rely on the order of the SP's parameters. Better to name the Stored Proc's params and give parameterized values to those.
In order to use Named params when calling your SP, without worrying about the order of parameters
Using SQL Server named parameters with ExecuteStoreQuery and ExecuteStoreCommand
Describes the best approach. Better than Dan Mork's answer here.
E.g.:
var cmdText = "[DoStuff] @Name = @name_param, @Age = @age_param";
var sqlParams = new[]{
new SqlParameter("name_param", "Josh"),
new SqlParameter("age_param", 45)
};
context.Database.SqlQuery(cmdText, sqlParams)