我正在尝试使用Database.SqlQuery
从EF5执行存储过程。但是第二个参数在这里没有认识到。
错误:“参数化查询”(@custNum nvarchar(7),@ PopDisc bigint,@ SecaryDisc bigint)'需要参数'@PrimaryDisc',这是未提供的。“
代码
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>();
这里有什么问题?
答案 0 :(得分:1)
这篇文章对我有用。
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>();