
Untitled
By: a guest on
Jun 14th, 2012 | syntax:
None | size: 1.27 KB | hits: 18 | expires: Never
How can I migrate a temp table using LINQ to SQL?
// migrate temp profile(s)...
var tempProfilesToMigrate = from ct in db.contact_temps
where ct.SessionKey == contact.Profile.SessionId
select new contact();
db.contacts.InsertAllOnSubmit(tempProfilesToMigrate);
db.SubmitChanges();
//...clear temp table records
var tempProfilesToDelete = from ct in db.contact_temps
where ct.SessionKey == contact.Profile.SessionId
select ct;
db.contact_temps.DeleteAllOnSubmit(tempProfilesToDelete);
db.SubmitChanges();
// migrate temp profile(s)...
var tempProfiles = from ct in db.contact_temps
where ct.SessionKey == contact.Profile.SessionId
select ct;
foreach (var c in tempProfiles)
{
Contact newC = new Contact();
newC.Name = c.Name;
// copy other values
db.contacts.InsertOnSubmit(newC);
}
// WAIT! do it at once in a single TX => avoid db.SubmitChanges() here.
db.contact_temps.DeleteAllOnSubmit(tempProfiles);
// Both sets of changes in one Tx.
db.SubmitChanges();