Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create temp table with Entity Framework

I want to create a temp table in sql server by using Entity Framework. Is there any way I can do this? If I can create a temp table, my next question is, how I can read it?

Thanks in advance.

André

like image 736
Andre Avatar asked Nov 12 '22 02:11

Andre


1 Answers

Ok, so you don't like the stored procedures route....nor do I to be honest, but it's the quickest way I could think of doing it.

Based on that, I don't know of any easy way in EDM to create temp tables so my next suggestion would be to create local objects, which mimic the temporary table you wish to create. The name temporary obviously indicates you don't want them to live on the database indefinitely, so using in memory objects has the benefit of being much more controllable and (depending on your latency) quicker than making multiple calls to a database.

public class MyTempTable
{
    public string ID { get; set; }
    public string Column1 { get; set; }
    // your other columns here
}

List<MyTempTable> tempTable = new List<MyTempTable>();

Once you've created your list of objects you can do basically anything you'd normally do on the database table using Linq.

like image 110
Andrew Avatar answered Nov 14 '22 22:11

Andrew