Home

how to insert results to sql table? (Specifically where to reference destination table)

Looked at a few examples to insert data(links below) but dont see the syntax to reference the destination table.

Whats the LINQ version of INSERT INTO Table2 based on SQL code below?
--append to table INSERT INTO table2 SELECT * FROM table1

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/linq/insert-update-and-delete-operations

Comments

  • This is the simplest I can come out with:

    var NewTable2Entities = Table1.Select(Table1Entity => new Table2Entity() {Property1 = Table1Entity.Property1, Property2 = Table1Entity.Property2}); Table2.InsertAllOnSubmit(NewTable2Entities); SubmitChanges();

    Give it a try!
Sign In or Register to comment.