实体框架返回整数而不是表数据?

时间:2017-07-19 13:51:23

标签: sql-server entity-framework stored-procedures

enter image description here

USE [prjMarlin]
    GO
    /****** Object:  StoredProcedure [dbo].[CriticalDateDiary]    Script Date: 19/07/2017 3:55:51 PM ******/
    SET ANSI_NULLS OFF
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    ALTER  PROCEDURE  [dbo].[CriticalDateDiary]

    AS

     SET NOCOUNT  ON

    DECLARE @ColumnsTable TABLE ([ColumnName] VARCHAR(50));

    INSERT INTO @ColumnsTable ([ColumnName])
    SELECT DISTINCT '[' + CONVERT(VARCHAR(48), WFStepName) + ']'
    FROM   vwTenureWorkFlowStepReport       
    --where WorkFlowId='a5a23e7e-31ea-439e-b823-179a3bd731ec' 


    DECLARE @PivotColumns VARCHAR(MAX), @TotalColumn VARCHAR(MAX), @SQL VARCHAR(MAX);

    SET @PivotColumns = (SELECT STUFF((SELECT DISTINCT ', ' + CONVERT(VARCHAR(50), [ColumnName])
                                       FROM   @ColumnsTable
                                       FOR XML PATH('')), 1, 2, ''));


    SET @TotalColumn = (SELECT STUFF((SELECT DISTINCT ' + ISNULL(' + CONVERT(VARCHAR(50), [ColumnName]) + ', 0)'
                                      FROM   @ColumnsTable
                                      FOR XML PATH('')), 1, 3, ''));

    SET @SQL = 'SELECT *, (' + @TotalColumn + ') AS [Total]
    FROM   (SELECT Tenure,GETDATE() AS CurrentTime,[WFStepName],[StepExpectedEndTime]
            FROM   [vwRunningTenureWorkFlowStepReport]) AS t 
           PIVOT (MAX([StepExpectedEndTime])  FOR WFStepName IN (' + @PivotColumns + ')) AS p;';


    exec(@SQL)

当我首先通过实体框架使用数据库时,这个存储过程被检测为整数的返回类型而不是表数据?有什么建议吗?

1 个答案:

答案 0 :(得分:0)

找不到令人满意的方法,因此我创建了一个脚本来生成一个表作为最终结果。