EF can't infer return schema from Stored Procedure selecting from a #temp table

后端 未结 4 1869
迷失自我
迷失自我 2020-11-27 03:02

Suppose the following:

CREATE PROCEDURE [MySPROC]
AS 
BEGIN

CREATE TABLE #tempSubset(
    [MyPrimaryKey] [bigint]  NOT NULL,
    [OtherColumn]  [int]     NO         


        
4条回答
  •  一个人的身影
    2020-11-27 03:37

    This is incomplete but when set fmtonly off does not work, you can generate the data contract using the following:

            SELECT * 
            FROM tempdb.sys.columns 
            WHERE [object_id] = OBJECT_ID(N'tempdb..#u');
    
            select case  system_type_id 
            when 62 then 'cast(null as float) as ' 
            when 175 then 'cast(null as char(' + cast(max_length as varchar(50)) + ')) as ' 
            when 167 then 'cast(null as varchar(' + cast(max_length as varchar(50)) + ')) as ' 
            when 56 then 'cast(null as int) as ' 
            when 104 then 'cast(null as bit) as ' 
            when 106 then 'cast(null as decimal(' + cast(precision as varchar(50)) + ',' + cast(scale as varchar(50)) + ')) as ' 
            when 40 then 'cast(null as date) as '            
            end
            + name + ','
            from  tempdb.sys.columns 
            WHERE [object_id] = OBJECT_ID(N'tempdb..#u');
    

提交回复
热议问题