Search code examples
c#sql-servercrudtemp-tablespetapoco

How can I create a temporary table using PetaPoco?


I need to check if a temporary table exist, delete it, create it and generally perform crud operations on this table using PetaPoco and C# like the following example. How can I do it?

IF OBJECT_ID('tempdb..#MyTempTable') IS NOT NULL BEGIN
   DROP TABLE #MyTempTable
END
CREATE TABLE #MyTempTable (phone VARCHAR (10) COLLATE Modern_Spanish_CI_AS)

INSERT INTO #MyTempTable (phone) ...
SELECT * FROM #MyTempTable
... etc ...

Solution

  • Even if you can (I haven't tried), the point of temp tables it's a temp space where to store thing when you are writing stored procedures.

    If you are using PetaPoco it's much better to use C# memory structures (like List) to store the temp values.