使用Entity Framework调用存储过程的问题:expects参数未提供 [英] Problems calling a stored procedure using Entity Framework: expects parameter not supplied
问题描述
我有以下存储过程:
CREATEA PROCEDURE USP_U_Pricing
(
@ProductId int
)
AS
BEGIN
....
END
我设置了这样的DbParameter:
var pProductId = dataProvider.GetParameter(); //返回一个DbParameter
pProductId.ParameterName =@ProductId;
pProductId.Value = productId;
pProductId.DbType = DbType.Int32;
并调用像这样的过程:
this.Database.SqlQuery< TEntity>(USP_U_Pricing,参数).ToList();
其中定价是SP名称和参数,只包含pProduct对象的数组。在这里,我检查了。
当这行执行时,我得到以下异常:
过程或函数'USP_U_Pricing'预计未提供参数'@ProductId'。
一直在阅读并测试不同的方式来设置参数,但没有结果。
如果我设置两个参数,一个称为ProductId,另一个为@ProductId,我得到一个错误,参数名称应该是唯一的....
可以你帮助我吗?
编辑:参数是一个包含参数信息的数组。它被填充,因为我调用了一个这样的签名的方法:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $执行脚本程序< TEntity>(string commandText,params object []参数)将pre pre
将pProductId作为参数传递:
dbContext.ExecuteStoredProcedureList< PricingInfo>(
USP_U_Pricing,
pProductId);
你可以试试这个。
this.Database.SqlQuery< TEntity>(EXEC USP_U_Pricing @ProductId,pProductID);
顺便说一句,在你的代码中,我看不到创建的参数参数传递到SqlQuery。
I have the following stored procedure:
CREATEA PROCEDURE USP_U_Pricing
(
@ProductId int
)
AS
BEGIN
....
END
I setup the DbParameter like this:
var pProductId = dataProvider.GetParameter(); //This returns a DbParameter
pProductId.ParameterName = "@ProductId";
pProductId.Value = productId;
pProductId.DbType = DbType.Int32;
And call the procedure like This:
this.Database.SqlQuery<TEntity>("USP_U_Pricing", parameters).ToList();
Where pricing is the SP name and parameters an array that contains only the pProduct object. It is there, I checked.
When this line is executed, I get the following exception:
Procedure or function 'USP_U_Pricing' expects parameter '@ProductId', which was not supplied.
I've been reading around and testing different ways to set the parameter up, but no result. If I set two parameters, one called ProductId and the other @ProductId, I get an error that the parameter name should be unique....
Can you help me please?
EDIT: parameters is an array that contains the parameter information. It is populated because I call a method with this signature:
ExecuteStoredProcedureList<TEntity>(string commandText, params object[] parameters)
Passing the pProductId as parameter:
dbContext.ExecuteStoredProcedureList<PricingInfo>(
"USP_U_Pricing",
pProductId);
Could you try with this.
this.Database.SqlQuery<TEntity>("EXEC USP_U_Pricing @ProductId", pProductID);
By the way, in your code I can't see the creation of the 'parameters' argument passed to SqlQuery.
这篇关于使用Entity Framework调用存储过程的问题:expects参数未提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!