I apologise for asking just a basic question, however I cannot find the cause of this error.
我为问一个基本问题而道歉,但是我找不到这个错误的原因。
I am using Entity Framework to execute a Stored Procedure, and I am passing in four parameters, however the SQL Database seems to reject them. Can anyone point me in the right direction?
我正在使用Entity Framework来执行存储过程,并且我传递了四个参数,但SQL数据库似乎拒绝它们。谁能指出我正确的方向?
My code:
我的代码:
ObjectResult<SearchDirectoryItem> resultList = container.ExecuteStoreQuery<SearchDirectoryItem>("SearchDirectoryEntries",
new SqlParameter("@DirectoryId", search.DirectoryId),
new SqlParameter("@Latitude", point.Latitude),
new SqlParameter("@Longitude", point.Longitude),
new SqlParameter("@Range", search.RangeMiles));
Which produces the error:
哪会产生错误:
Procedure or function 'SearchDirectoryEntries' expects parameter '@DirectoryId', which was not supplied.
过程或函数'SearchDirectoryEntries'需要参数'@DirectoryId',这是未提供的。
The SQL generated is:
生成的SQL是:
exec sp_executesql N'SearchDirectoryEntries',N'@DirectoryId int,@Latitude decimal(7,5),@Longitude decimal(6,5),@Range int',@DirectoryId=3,@Latitude=53.36993,@Longitude=-2.37013,@Range=10
The stored procedures is:
存储过程是:
ALTER PROCEDURE [dbo].[SearchDirectoryEntries]
@DirectoryId int,
@Latitude decimal(18, 6),
@Longitude decimal(18, 6),
@Range int
Many Thanks.
非常感谢。
1 个解决方案
#1
22
The commandText param in your query is incorrect. It should be a call to a stored procedure with parameters instead of just stored procedure name:
查询中的commandText参数不正确。它应该是一个带参数的存储过程调用,而不仅仅是存储过程名称:
ObjectResult<SearchDirectoryItem> resultList = container.ExecuteStoreQuery<SearchDirectoryItem>(
"Exec SearchDirectoryEntries @DirectoryId, @Latitude, @Longitude, @Range",
new SqlParameter("DirectoryId", search.DirectoryId),
new SqlParameter("Latitude", point.Latitude),
new SqlParameter("Longitude", point.Longitude),
new SqlParameter("Range", search.RangeMiles));
Also don't forget to remove '@' from SqlParameter constructor.
另外,不要忘记从SqlParameter构造函数中删除“@”。
#1
22
The commandText param in your query is incorrect. It should be a call to a stored procedure with parameters instead of just stored procedure name:
查询中的commandText参数不正确。它应该是一个带参数的存储过程调用,而不仅仅是存储过程名称:
ObjectResult<SearchDirectoryItem> resultList = container.ExecuteStoreQuery<SearchDirectoryItem>(
"Exec SearchDirectoryEntries @DirectoryId, @Latitude, @Longitude, @Range",
new SqlParameter("DirectoryId", search.DirectoryId),
new SqlParameter("Latitude", point.Latitude),
new SqlParameter("Longitude", point.Longitude),
new SqlParameter("Range", search.RangeMiles));
Also don't forget to remove '@' from SqlParameter constructor.
另外,不要忘记从SqlParameter构造函数中删除“@”。