Why can't Entity Framework see my Stored Procedure's column information?

后端 未结 10 1329
终归单人心
终归单人心 2020-12-02 14:54

I have the following stored procedure and when I attempt to Function Import it says my Stored Procedure returns no columns. What am I missing? Any Suggestions?

The

10条回答
  •  感动是毒
    2020-12-02 15:14

    Just add the select statement without the quotation, execute the stored proc, go get update the model, edit your function import and get column information. This should populate the new columns. Update the result set and go back to your stored proc and remove the select list you just added. And execute the stored proc. This way your columns will get populated in the result set. See below where to add the select list without quote.

        ALTER PROCEDURE [healthc].[ev_kc_Products_Search]
    (
        @SearchString   VARCHAR(1000)
    )
    
    AS
    SET NOCOUNT ON;
    SELECT  VendorID ID,
            Name VendorName,
            NULL ItemName,
            ''V'' Type,
            0 Sequence
        FROM    tblVendors
    
    DECLARE @SQL    VARCHAR(max),
        @SQL1   VARCHAR(max),
        @Tag    VARCHAR(5)
    
    CREATE TABLE #T
    (   ID      INT,
        VendorName  VARCHAR(255),
        ItemName        VARCHAR(255),
        Type        VARCHAR(2),
        Sequence        TINYINT
    )
    

    SET @SQL = '

    INSERT  #T
    
    SELECT  VendorID ID,
        Name VendorName,
        NULL ItemName,
        ''V'' Type,
        0 Sequence
    FROM    tblVendors
    WHERE   '+REPLACE(@SQL1,@Tag,'Name')+'
    
    UNION ALL
    
    BLAH BLAH BLAH'
    

    EXEC(@SQL)

    SELECT ID, VendorName, ItemName, Type FROM #T

    I hope this helps someone out there.

提交回复
热议问题