Insert Select for mass inserts
Posted: Fri 20 May 2011 23:10
Hi, wondering if there is a good way to perform a mass insert without submitting a single insert statement for each row using LINQ.
I've tried a few ways of doing this myself using reflection and getting the real DB table names from the attributes, but was ultimately foiled by the way constants aren't included in the SQL generated from an IQeryable object.
variable "sql" will actually be "Select id from table1" and not include the date... I'm guessing that way of achieving my goal is not going to work.
Any possible solutions?
Thanks,
zach
Code: Select all
insert into Table1 (Table1.Col1, Table1.Col2)
select Table2.Col1, Table2.Col2
from Table2
Code: Select all
dim dc as new dataContext
dim aDate as DateTime = #1/1/2001#
dim query = From t in dc.Table1 _
Select new with {.ID = t.ID, .Date = aDate}
dim sql = dc.GetCommand(query).CommandText
Any possible solutions?
Thanks,
zach