I am using Entity Framework 6 and Microsoft SQL Server 2012.
Here is my stored procedure:
ALTER PROCEDURE SPDeleteRegion
@siteId int,
@regionId int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @isDeleted BIT
IF EXISTS (SELECT 1 FROM SiteObjects WHERE SiteRegionId = @regionId)
BEGIN
SET @isDeleted = 0 ; --not deleted
RETURN @isDeleted;
END
ELSE
BEGIN
--do what needs to be done if not
DELETE FROM SiteRegions
WHERE Id = @regionId;
SET @isDeleted = 1; -- deleted
RETURN @isDeleted;
END
END
Here how I call the stored procedure in C#:
var t = _context.Database.SqlQuery<bool>("SPDeleteRegion @siteId, @regionId",
new SqlParameter("@siteId", siteId),
new SqlParameter("@regionId", regionId));
On the line of code above I get this exception:
The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types.
Any idea why I get the excewption and how to fix it?
boolas a type parameter_context.Database.SqlQuery<bool>? Your procedure does not return anything - Adil MammadovisDeletedat procedure declaration. - Adil MammadovINT(or bigint) - typically it signals how many rows were affected by anINSERT,UPDATEorDELETEoperation. You cannot send back abitusing theRETURNkeyword - you need to use either anOUTPUTparameter, or you need to select yourbitand thus return a result set - marc_s