繁体   English   中英

EntityFramework过程或函数''期望参数'',未提供

[英]EntityFramework Procedure or function '' expects parameter '', which was not supplied

我为问一个基本问题而道歉,但是我找不到这个错误的原因。

我正在使用Entity Framework来执行存储过程,我传递了四个参数,但是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

非常感谢。

查询中的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));

另外,不要忘记从SqlParameter构造函数中删除“@”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM