EntityFramework过程或函数“期望参数”,未提供 [英] EntityFramework Procedure or function '' expects parameter '', which was not supplied

查看:88
本文介绍了EntityFramework过程或函数“期望参数”,未提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉仅问一个基本问题,但是找不到该错误的原因。

I apologise for asking just a basic question, however I cannot find the cause of this error.

我正在使用Entity Framework执行存储过程,并且我我传入了四个参数,但是SQL数据库似乎拒绝了它们。有人可以指出我正确的方向吗?

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?

我的代码:

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'。

Procedure or function 'SearchDirectoryEntries' expects parameter '@DirectoryId', which was not supplied.

生成的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参数您的查询中不正确。它应该是对带有参数的存储过程的调用,而不仅仅是存储过程的名称:

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:

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构造函数中删除 @。

Also don't forget to remove '@' from SqlParameter constructor.

这篇关于EntityFramework过程或函数“期望参数”,未提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆