I have the following code which accepts a DataTable and iterates through the properties, then saves the data. I am looking for a more efficient way of processing this so that I do not have to manually hard-code the ItemArray counts as well as the row names. Can anyone provide details on how I can improve this?
IList<account_dim_temp> a1 = new List<account_dim_temp>();
foreach (DataRow row in data.Rows)
{
account_dim_temp a = new account_dim_temp();
a.account_id = (string) row.ItemArray[0].ToString().Replace("\\N", "");
a.canvas_id = (string) row.ItemArray[1].ToString().Replace("\\N", "");
a.name = (string) row.ItemArray[2].ToString().Replace("\\N", "");
a.depth = (string) row.ItemArray[3].ToString().Replace("\\N", "");
a.workflow_state = (string) row.ItemArray[4].ToString().Replace("\\N", "");
a.parent_account = (string) row.ItemArray[5].ToString().Replace("\\N", "");
a.parent_account_id = (string) row.ItemArray[6].ToString().Replace("\\N", "");
a.grandparent_account = (string) row.ItemArray[7].ToString().Replace("\\N", "");
a.grandparent_account_id = (string) row.ItemArray[8].ToString().Replace("\\N", "");
a.root_account = (string) row.ItemArray[9].ToString().Replace("\\N", "");
a.root_account_id = (string) row.ItemArray[10].ToString().Replace("\\N", "");
a.subaccount1 = (string) row.ItemArray[11].ToString().Replace("\\N", "");
a.subaccount1_id = (string) row.ItemArray[12].ToString().Replace("\\N", "");
a.subaccount2 = (string) row.ItemArray[13].ToString().Replace("\\N", "");
a.subaccount2_id = (string) row.ItemArray[14].ToString().Replace("\\N", "");
a.subaccount3 = (string) row.ItemArray[15].ToString().Replace("\\N", "");
a.subaccount3_id = (string) row.ItemArray[16].ToString().Replace("\\N", "");
a.subaccount4 = (string) row.ItemArray[17].ToString().Replace("\\N", "");
a.subaccount4_id = (string) row.ItemArray[18].ToString().Replace("\\N", "");
a.subaccount5 = (string) row.ItemArray[19].ToString().Replace("\\N", "");
a.subaccount5_id = (string) row.ItemArray[20].ToString().Replace("\\N", "");
a.subaccount6 = (string) row.ItemArray[21].ToString().Replace("\\N", "");
a.subaccount6_id = (string) row.ItemArray[22].ToString().Replace("\\N", "");
a.subaccount7 = (string) row.ItemArray[23].ToString().Replace("\\N", "");
a.subaccount7_id = (string) row.ItemArray[24].ToString().Replace("\\N", "");
a.subaccount8 = (string) row.ItemArray[25].ToString().Replace("\\N", "");
a.subaccount8_id = (string) row.ItemArray[26].ToString().Replace("\\N", "");
a.subaccount9 = (string) row.ItemArray[27].ToString().Replace("\\N", "");
a.subaccount9_id = (string) row.ItemArray[28].ToString().Replace("\\N", "");
a.subaccount10 = (string) row.ItemArray[29].ToString().Replace("\\N", "");
a.subaccount10_id = (string) row.ItemArray[30].ToString().Replace("\\N", "");
a.subaccount11 = (string) row.ItemArray[31].ToString().Replace("\\N", "");
a.subaccount11_id = (string) row.ItemArray[32].ToString().Replace("\\N", "");
a.subaccount12 = (string) row.ItemArray[33].ToString().Replace("\\N", "");
a.subaccount12_id = (string) row.ItemArray[34].ToString().Replace("\\N", "");
a.subaccount13 = (string) row.ItemArray[35].ToString().Replace("\\N", "");
a.subaccount13_id = (string) row.ItemArray[36].ToString().Replace("\\N", "");
a.subaccount14 = (string) row.ItemArray[37].ToString().Replace("\\N", "");
a.subaccount14_id = (string) row.ItemArray[38].ToString().Replace("\\N", "");
a.subaccount15 = (string) row.ItemArray[39].ToString().Replace("\\N", "");
a.subaccount15_id = (string) row.ItemArray[40].ToString().Replace("\\N", "");
a.sis_source_id = (string) row.ItemArray[41].ToString().Replace("\\N", "");
a1.Add(a);
}
db.account_dim_temp.AddRange(a1);
db.SaveChanges();