trying to execute the stored proc in EF using the following code:
var params = new object[] {new SqlParameter("@FirstName", "Bob")};
return this._repositoryContext.ObjectContext.ExecuteStoreQuery<ResultType>("GetByName", params);
but keep getting this error:
Procedure or function 'GetByName' expects parameter '@FirstName', which was not supplied.
and from sql profiler:
exec sp_executesql N'GetByName',N'@FirstName nvarchar(100),@FirstName=N'Bob'
what is wrong wit the above ExecuteStoreQuery code?
Ignoring the fact that params
is a reserved word...
Think your query needs to be:
var params = new object[] {new SqlParameter("@FirstName", "Bob")};
return this._repositoryContext.ObjectContext.ExecuteStoreQuery<ResultType>("exec GetByName @FirstName", params);
Should also say that if that proc is a standard part of your database and data model then you should import it into your EDM so it's available directly on your context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With