I'm retrieving two lists of datasets using Linq to entities. They're both in the same Database, but I need to get one table converted into my Tasks Table because it's integrated into my Calendar. Not worth going into extreme detail here I'm sure but I would love to speed up the process of matching id's and Creating new Task objects. This is a Once and done snippet so even at a slow speed I can simply leave the program running overnight. However, for future reference I'd like some suggestions on increasing the efficiency.
var accounts = data.Accounts.ToList().OrderBy(a => a.ID);
Incidents[] Incidents = data.Incidents.ToArray();
for (int i=0;i<Incidents.Length;i++)
{
foreach (var a in accounts)
{
if (a.Acct_CID == Incidents[i].CustomerID)
{
Tasks t = new Tasks();
t.creator_id = a.ID;
t.start_date = Incidents[i].DateOpened;
t.end_date = Incidents[i].DateCLosed;
t.product_code = Incidents[i].ProductCode;
t.install_type = Incidents[i].InstallType;
t.os = Incidents[i].OSType;
t.details = Incidents[i].Description;
t.solution = Incidents[i].Solution;
t.creator_name = Incidents[i].TechID;
t.category = Incidents[i].Title;
t.text = "Ticket for" + " " + Incidents[i].Name;
if (t.end_date == DateTime.MinValue || t.end_date == null)
t.status_id = 6;
else t.status_id = 7;
data.Tasks.Add(t);
break;
}
}
}
data.SaveChanges();