0

I have the following stored procedure:

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[GetData]
    @taskName VARCHAR(205) = NULL
AS
BEGIN
    SELECT  *
    FROM    [dbo].[Table] WITH (NOLOCK)
    WHERE   @taskName IS NULL 
            OR @taskName = '' 
            OR Name LIKE '%' + @taskName + '%'
    ORDER BY Name
END

Now I created an File.edmx generated model, selected the GetData stored procedure, when I do a function import and I get "Get Column Information", it says

The selected stored procedure returns no columns

I am dbo_owner on the database and it is my user that is in the app.config on generation, and I am even storing the password in app.config (temporarily), when I run the procedure from Management Studio, it shows the columns..

I'm puzzled!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
jaekie
  • 2,283
  • 4
  • 30
  • 52

3 Answers3

1

You need to specify the field names in your select statement rather than just using the *

GrahamJRoy
  • 1,603
  • 5
  • 26
  • 56
  • Added all the columns instead of *, deleted the Stored Procedure in the Model, re-generated, still same problem, says it returns no columns – jaekie May 16 '12 at 15:19
1

try

ALTER PROCEDURE [dbo].[GetData]
@taskName VARCHAR(205) = NULL
AS
BEGIN
    exec ('SELECT * FROM [dbo].[Table] WITH (NOLOCK) WHERE ' + @taskName + 'IS NULL OR ' + @taskName + ' = \'\' OR Name LIKE \'%' + @taskName + '%\' ORDER BY Name')
END
GO
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • I tried this, didn't work.. but being puzzled again, I deleted the EDMX and tried again, works now, musta been a fluke – jaekie May 16 '12 at 15:36
0

I would try the same process but using only

SELECT  *
FROM    [dbo].[Table] WITH (NOLOCK)

instead of the full query. Then you can alter your proc to add the where.

Sometimes EF has problems identifying the return columns due to the were clause

Diego
  • 34,802
  • 21
  • 91
  • 134