C# 实体框架程序或功能'';应为参数'';,这是没有提供的
我很抱歉只问了一个基本的问题,但是我找不到这个错误的原因 我使用实体框架来执行一个存储过程,我传入了四个参数,但是SQL数据库似乎拒绝了它们。谁能给我指出正确的方向吗 我的代码:C# 实体框架程序或功能'';应为参数'';,这是没有提供的,c#,sql,entity-framework,C#,Sql,Entity Framework,我很抱歉只问了一个基本的问题,但是我找不到这个错误的原因 我使用实体框架来执行一个存储过程,我传入了四个参数,但是SQL数据库似乎拒绝了它们。谁能给我指出正确的方向吗 我的代码: ObjectResult<SearchDirectoryItem> resultList = container.ExecuteStoreQuery<SearchDirectoryItem>("SearchDirectoryEntries", new SqlParamet
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));
存储过程是:
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));
ObjectResult resultList=container.ExecuteStoreQuery(
“Exec SearchDirectoryEntries@DirectoryId、@Latitude、@Longitude、@Range”,
新的SqlParameter(“DirectoryId”,search.DirectoryId),
新参数(“纬度”,点纬度),
新的SqlParameter(“经度”,point.Longitude),
新的SqlParameter(“Range”,search.RangeMiles));
另外,不要忘记从SqlParameter构造函数中删除“@”。您能发布SQL存储过程的声明吗?到定义参数的位置为止?ALTER PROCEDURE[dbo].[SearchDirectoryEntries]@DirectoryId int、@Latitude decimal(18,6)、@Latitude decimal(18,6)、@Range int cheers
搜索和点的定义是什么?i、 e.Issearch.DirectoryId
anint
?所有值都不为空,它们都被传递给SQL:exec sp_executesql N'SearchDirectoryEntries',N'@DirectoryId int,@Latitude decimal(7,5),@Range decimal(6,5),@Range int',@DirectoryId=3,@Latitude=53.36993,@Longitude=-2.37013,@Range=10谢谢!在多次错误启动后完全修复了我的问题。SqlParameter
的文档中没有指定从名称中删除@
。那是从哪里来的?但是,如果使用的是ObjectParameter
,则必须将其删除。
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));