I have the following stored procedure :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SearchMediaTitles]
@query varchar(50),
@limit int = 6,
@userId int
AS
SET FMTONLY OFF
BEGIN
declare @searchString varchar(52)
set @searchString = '"' + @query +'*"'
IF @userId!=NULL
SELECT TOP (@limit) ID, Title from Media where CONTAINS([Title], @searchString)
AND ID IN
(
SELECT FavoriteMedia_ID
FROM dbo.UserMedia
WHERE UserMedia_Media_ID=@userId
)
ELSE
SELECT TOP (@limit) ID, Title from Media where CONTAINS([Title], @searchString)
END
In Entity Framework when I try to map it at function import for a complex type it says
the selected stored procedure returns no columns
I've read about this on the internet and I found out I need to set SET FMTONLY OFF, but as you can see it didn't work.
Any ideas?
EDIT:
I've changed SELECT to * and it return an empty result. I think it's related to problem described above
SELECT ID, Title from Mediaso it is a simple straight forward proc with no conditional logic then do the entity framework mapping then put your original code back as both paths look like they will return a resultset of that shape.SET FMTONLYstatement? Also is this something specific to that stored proc or do you get this for all stored procedures?SELECT ID, Title from Mediayou didn't leaveTOP(@limit)in there? According to this thread that might mess things up as EF will passNULLfor all parameters. And that will cause an error forTOP