簡體   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