Mapping LINQ to SQL table to another very similar table without iterating through every one
Posted
by Daniel Coffman
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Coffman
Published on 2010-04-08T21:47:13Z
Indexed on
2010/04/08
21:53 UTC
Read the original article
Hit count: 157
Apologies for the vague question. Here it is: I have a table object created by LINQ to SQL. I am copying entries from one table to an "archive" table that has all the columns of the original, plus a couple extra ones.
It feels sloppy to iterate through every object and manually define the mapping like:
foreach (oldTable in dbContextOldTables)
{
var newTable = new NewTable();
newTable.TableID = oldTable.ID;
newTable.Title = oldTable.Title;
... (repeat for twenty columns)
newTable.ColumnThatIsntInOldTable = "Data that will be the same for every row";
dbContext.NewTables.InsertOnSubmit(newTable);
}
dbContext.SubmitChanges();
Is there a clever way to do this?
© Stack Overflow or respective owner