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. AS
  3. BEGIN
  4. SET NOCOUNT ON;
  5. IF 1=0 BEGIN
  6. SET FMTONLY OFF
  7. END
  8. CREATE TABLE #Temp
  9. (
  10. ProductID integer NOT NULL,
  11. Name nvarchar(50) COLLATE DATABASE_DEFAULT NOT NULL
  12. );
  13. INSERT INTO #Temp
  14. ([ProductID], [Name])
  15. SELECT
  16. p.[ProductID], p.[Name]
  17. FROM Production.Product AS p
  18. SELECT
  19. t.[Name], t.[ProductID]
  20. FROM #Temp AS t
  21. DROP TABLE #Temp;
  22. END;

Conclusion

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