I have to follow rule that stored procedure has to be executed in "parameterized way". I believe that its about SQL Injection protection. I want to know if following code can be considered as "parameterized execution" and is SQL Injection protected.
return Database.SqlQuery<Program>(
String.Format("usp_GetPrograms {0},{1},{2},{3}",
pID, pDisplayStart, pDisplayLength, pSearchString)
).ToList();
Otherway i can rewrite it to something like that
context.Database.SqlQuery<myEntityType>(
"mySpName @param1, @param2, @param3",
new SqlParameter("param1", param1),
new SqlParameter("param2", param2),
new SqlParameter("param3", param3)
);
Iam asking because the program is complete and tested and ready to production and i dont want to rewrite the code and risk that something will broke.
What do you think about these two approaches ?
Additional question: Is SqlParameter() necessary according to
"Loading entities from stored procedures" section ?
Additional question2: How can i pass Nullable parameter ?