I am trying to execute a stored procedure from EF5 using Database.SqlQuery
. But 2nd parameter is not recognizing here.
Error: "The parameterized query '(@custNum nvarchar(7), @PrimaryDisc bigint, @SecondaryDisc bigint)' expects the parameter '@PrimaryDisc', which was not supplied."
Code
var results = _MiscContext.Database.SqlQuery<TempTechDisciplines>(
"exec sp_getTechnicalDiscipline @CustNum, @PrimaryDisc, @SecondaryDisc",
new SqlParameter("custNum", CustomerNum),
new SqlParameter("PrimaryDisc",SqlDbType.BigInt, 0),
new SqlParameter("SecondaryDisc",SqlDbType.BigInt, 0))
.ToList<TempTechDisciplines>();
What is the issue here?
It works for me from this article.
var custNum = new SqlParameter {ParameterName = "CustNum", Value = CustomerNum};
var primaryDisc = new SqlParameter { ParameterName = "PrimaryDisc", Value = 0 };
var secondaryDisc = new SqlParameter { ParameterName = "SecondaryDisc", Value = 0 };
var results = _MiscContext.Database.SqlQuery<TempTechDisciplines>(
"exec sp_getTechnicalDiscipline @CustNum, @PrimaryDisc,
@SecondaryDisc",
custNum,primaryDisc,secondaryDisc).ToList<TempTechDisciplines>();
If a parameter value ( CustomerNum
) is null, the parameter will not be serialized, and this error will occur.
Check and add default values for each parameter you add ( '0' for CustomerNum
), and check if CustomerNum <> 0
instead IS NULL
if needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.