Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute stored proc in ExecuteStoreQuery EF. is this a bug in EF?

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?

like image 303
user384080 Avatar asked Dec 16 '22 01:12

user384080


1 Answers

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.

like image 163
dezfowler Avatar answered May 14 '23 06:05

dezfowler