【发布时间】:2010-03-22 15:30:14
【问题描述】:
我很抱歉只问了一个基本问题,但是我找不到这个错误的原因。
我正在使用实体框架执行存储过程,并传入四个参数,但是 SQL 数据库似乎拒绝了它们。谁能指出我正确的方向?
我的代码:
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));
产生错误的原因:
过程或函数“SearchDirectoryEntries”需要参数“@DirectoryId”,但未提供。
生成的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
存储过程是:
ALTER PROCEDURE [dbo].[SearchDirectoryEntries]
@DirectoryId int,
@Latitude decimal(18, 6),
@Longitude decimal(18, 6),
@Range int
非常感谢。
【问题讨论】:
-
你能发布你的SQL存储过程的声明吗?到哪里定义参数?
-
ALTER PROCEDURE [dbo].[SearchDirectoryEntries] @DirectoryId int, @Latitude decimal(18, 6), @Longitude decimal(18, 6), @Range int 干杯
-
search和point的定义是什么?即search.DirectoryId是int吗? -
没有一个值是空的,它们都传递给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
标签: c# sql entity-framework