0

I'm using LINQ to DB (linq2db, linq2db.EntityFrameworkCore) and want to use "select into" clause to create new table from query.

Something like this:

SELECT * INTO #TempTable FROM SourceTable

My classes:

public class TempTable {
    public long Id { get; set; }
    public DateTime TimeStamp { get; set; }
    public string TypeName { get; set; }
    public string TypeAbbr { get; set; }
    public static Expression<Func<SourceTable, TempTable>> CloneSourceTable => obj => new TempTable{...};
}
public class SourceTable {
    public long Id { get; set; }
    public DateTime TimeStamp { get; set; }
    public string TypeName { get; set; }
    public string TypeAbbr { get; set; }
    public string OwnerTitle { get; set; }
}

How can this be done using ling2db?

UPD If manually create a temporary table, then I can use code like this to copy the data:

Db.SourceTable.Insert(Db.TempTable.ToLinqToDBTable(), TempTable.CloneSourceTable());

But I'd like to create TempTable (#TempTable) via linq2db as a complete copy of SourceTable, rather than doing it manually.

Aries
  • 433
  • 7
  • 17
  • 1
    It is possible, but add more details with classes and when you need to create temporary table. – Svyatoslav Danyliv Jun 26 '23 at 14:36
  • @SvyatoslavDanyliv Thank you. I have updated my question and added examples – Aries Jun 27 '23 at 18:46
  • As I said above, I need to create a table and fill it with data at once, this can be done with one "SELECT * INTO" query, or in 2 separate steps: create a table and after fill it with data. But the main problem is that at the C# code I only have a general data model (class), but not the exact size of each text field, so the query "SELECT * INTO" solves this problem. – Aries Jun 27 '23 at 18:51
  • Well, sorry, currently we do not use filed information from source query for creating new temporary table. Looks like we have missed this case. – Svyatoslav Danyliv Jun 28 '23 at 08:51

0 Answers0