How To Add Temp Table Support In Entity Framework

Introduction 

 
Suppose you define a temp table in a procedure and retrieve the data from the table through the entity framework. It will not be accessible due to the absence of the schema in the EF. Therefore, you should define the table in the database. Below is an example of the procedure:
  1. CREATE PROCEDURE dbo.Demo  
  2.        
  3. AS  
  4. BEGIN  
  5.     SET NOCOUNT ON;  
  6.      IF 1=0 BEGIN  
  7.        SET FMTONLY OFF  
  8.      END  
  9.       
  10.     CREATE TABLE #Temp  
  11.     (  
  12.         ProductID   integer NOT NULL,  
  13.         Name        nvarchar(50) COLLATE DATABASE_DEFAULT NOT NULL  
  14.     );  
  15.       
  16.     INSERT INTO #Temp  
  17.         ([ProductID], [Name])  
  18.     SELECT  
  19.         p.[ProductID], p.[Name]  
  20.     FROM Production.Product AS p  
  21.        
  22.     SELECT  
  23.         t.[Name], t.[ProductID]  
  24.     FROM #Temp AS t  
  25.       
  26.     DROP TABLE #Temp;  
  27. END;   

Conclusion

 
In the above blog, we studied how to add temp table support in an entity framework.