0 votes
1 view
in SQL by (20.3k points)

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<myEntityType>("mySpName", param1, param2, param3);

At first I tried using SqlParameter objects as the params but this didn't work and threw a SqlException with the following message:

Procedure or function 'mySpName' expects parameter '@param1', which was not supplied.

So my question is how you can use this method with a stored procedure that expects parameters?

Thanks.

1 Answer

0 votes
by (40.3k points)

You should supply the SqlParameter instances in the following way:

context.Database.SqlQuery<myEntityType>(

    "mySpName @param1, @param2, @param3",

    new SqlParameter("param1", param1),

    new SqlParameter("param2", param2),

    new SqlParameter("param3", param3));

Related questions

0 votes
1 answer
0 votes
1 answer
asked May 8 in SQL by Sudhir_1997 (37.2k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...