EF6 fails to import stored procedure

Viewed 901

This is a simplified version of a stored procedure

ALTER PROCEDURE [dbo].[StoredProc1]
(
   @PageIndex INT = 1,
   @RecordCount INT = 20,
   @Gender NVARCHAR(10) = NULL
)
AS 
BEGIN
    SET NOCOUNT ON ;

WITH tmp1 AS
(   
    SELECT u.UserId, MIN(cl.ResultField) AS BestResult
      FROM [Users] u
        INNER JOIN Table1 tbl1 ON tbl1.UserId = u.UserId
     WHERE (@Gender IS NULL OR u.Gender = @Gender)
             GROUP BY u.UserID
     ORDER BY BestResult
       OFFSET @PageIndex * @RecordCount ROWS 
       FETCH NEXT @RecordCount ROWS ONLY
)       
SELECT t.UserId, t.BestResult, AVG(cl.ResultField) AS Average
INTO #TmpAverage
FROM tmp1 t 
  INNER JOIN Table1 tbl1 ON tbl1.UserId = t.UserId
GROUP BY t.UserID, t.BestResult
 ORDER BY Average

SELECT u.UserId, u.Name, u.Gender, t.BestResult, t.Average
  FROM #tmpAverage t
    INNER JOIN Users u on u.UserId = t.UserId

DROP TABLE #TmpAverage
END

When I use EF6 to load the stored procedure, and then go to the "Edit Function Import" dialog, no columns are displayed there. Even after I ask to Retrieve the Columns, I get the message that the SP does not return columns. When I execute the SP from SMMS, I get the expected [UserId, Name, Gender, BestResult, Average] list of records.

Any idea how can I tweak the stored procedure or EF6 to make it work? Thanks in advance

2 Answers
Related