JSBach
JSBach

Reputation: 4747

Problems calling a stored procedure using Entity Framework: expects parameter not supplied

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);

Upvotes: 0

Views: 3188

Answers (1)

Steve
Steve

Reputation: 216333

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.

Upvotes: 3

Related Questions