在ExecuteStoreQuery EF中执行存储过程。这是EF中的错误吗? [英] execute stored proc in ExecuteStoreQuery EF. is this a bug in EF?
问题描述
var params = new object [] {new SqlParameter (@FirstName,Bob)};
返回this._repositoryContext.ObjectContext.ExecuteStoreQuery< ResultType>(GetByName,params);
但不断收到此错误:
过程或函数'GetByName'期望参数'@FirstName',
未提供。
和sql profiler:
exec sp_executesql N'GetByName',N'@ FirstName nvarchar(100),@ FirstName = N'Bob'
上述ExecuteStoreQuery代码有什么问题?
忽略 params
是保留字的事实
认为您的查询需要:
var params = new object [] {new SqlParameter( @FirstName,Bob)};
返回this._repositoryContext.ObjectContext.ExecuteStoreQuery< ResultType>(exec GetByName @FirstName,params);
还应该说如果proc是数据库和数据模型的标准部分,那么你应该< a href =http://msdn.microsoft.com/en-us/library/bb896231.aspx =noreferrer>将其导入到您的EDM ,因此可以直接在您的上下文中使用。
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.
这篇关于在ExecuteStoreQuery EF中执行存储过程。这是EF中的错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!