I am trying to execute a three raw queries with Entity Framework.
The first query will basically create a temporary table. The second query will add an index on the temporary table. Finally, the second query will join to the temporary table to other table to get a final dataset.
But every time I run my code, get the following error
invalid
#allRecordsobject.
Here is what I have done
using (BaseContextdb = new BaseContext())
{
    using (var dbContextTransaction = db.Database.BeginTransaction())
    {
        try
        {
            db.Database.ExecuteSqlCommand("SELECT col1, col2, col3 " +
                                          "INTO #allRecords " +
                                          "FROM someTable " +
                                          "WHERE col5 = 'blab' " +
                                          "CREATE INDEX d ON #allRecords(col1, col2); ");
            var results = db.Database.SqlQuery<ResuleModel>(this.GetQuery()).ToList();
            db.SaveChanges();
            dbContextTransaction.Commit();
        }
        catch (Exception)
        {
            dbContextTransaction.Rollback();
        }
    }
}
how can I correctly create temporary table with Entity Framework?
UPDATED
Here is the query that is returned by this.GetQuery()
SELECT b.*, c.* 
FROM b
INNER JOIN #allRecords AS a ON a.col1 = v.col1 AND a.col2 = b.col2
INNER JOIN c ON c.Id= b.Id
...
...
...
 
     
     
     
     
    