EntityFramework The argument " is missing from the procedure or function ".

c# entity-framework sql


I apologize for asking such a simple question, but I am unable to identify the source of this problem.

I'm running a stored procedure using Entity Framework with four arguments, but the SQL Database appears to be rejecting them. Can someone please assist me in the proper path?

My key:

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));

This results in the mistake:

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

The resulting SQL is:

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

The stored instructions are:

ALTER PROCEDURE [dbo].[SearchDirectoryEntries]
@DirectoryId int,
@Latitude decimal(18, 6),
@Longitude decimal(18, 6),
@Range int

Thank you.

3/22/2010 4:04:00 PM

Accepted Answer

In your query, the commandText parameter is wrong. Instead than only calling the stored method by name, it should include parameters:

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));

Remember to delete "@" from the SqlParameter constructor as well.

6/10/2011 10:25:00 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow