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
For everyone who has the same problem, this is what I've done.
First I modified the stored procedure to a simple one like this :
SELECT [column1],[column2] FROM [table]
I imported it in Entity Framework
, created the complex type and mapping properties
Then I changed it back and updated the model and now it works. I think Entity Framework
has some problems with complex stored procedures. From what I read it can't get results for dynamic stored procedures or for a stored procedure which use temp tables
.
PS: When I call it with Ajax, I call it using data.column1 and data.column2
. If I use data.value' it returns
undefined` .
It's kinda weird.
EDIT: It's like Martin said but I don't know why it didn't worked in the first place ! Thank you btw !
I guess you are missing the single quotes on your prefix_term. So this:
set @searchString = '"' + @query +'*"'
Should be:
set @searchString = CHAR(39) + '"' + @query +'*"' + CHAR(39)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.