public static void Populate() { int totalRows = Program.TotalRows; int chunkSize = Program.ChunkSize; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.MonetaryTotals join t2 in db.Minings on t1.Alias equals t2.AnticipatedMonetaryTotal_Id orderby t2.Order_Id select t1).Skip(j).Take(chunkSize); List <Mining> miningRows = db.Minings.ToList(); int counter = 0; foreach (var item in query) { Mining rowUpdate = miningRows.Single(x => x.AnticipatedMonetaryTotal_Id == item.Alias); rowUpdate.PayableAmount_Value = item.PayableAmount_Value; rowUpdate.TaxInclusiveAmount_Value = item.TaxInclusiveAmount_Value; Console.WriteLine($"MonetaryTotal table: {j}, {counter}"); counter++; } db.SaveChanges(); } } }
public static void Populate() { int totalRows = Program.TotalRows; int chunkSize = Program.ChunkSize; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.Parties join t2 in db.Minings on t1.Order_Id equals t2.Order_Id orderby t1.Order_Id select t1).Skip(j).Take(chunkSize); var results = query.ToList(); List <Mining> miningRows = db.Minings.ToList(); for (int i = 0; i < chunkSize; i++) { Mining rowUpdate = miningRows.Single(x => x.Order_Id == results[i].Order_Id); rowUpdate.PartyIdentification = results[i].PartyIdentification; rowUpdate.PostalAddress_Id = results[i].PostalAddress_Id; Console.WriteLine($"Party table: {j}, {i}"); } db.SaveChanges(); } } }
public static void Populate() { int totalRows = Program.TotalRows; int chunkSize = Program.ChunkSize; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.Addresses join t2 in db.Minings on t1.Alias equals((t2.PostalAddress_Id) - 1) where t1.CityName != null orderby t2.Order_Id select t1).Skip(j).Take(chunkSize); // Due to the way the database is designed, the PostalAddress_Id doesn't exactly match the Alias // so you have to -1 in the query and then add it back on in the foreach loop to match it up. var results = query.ToList(); List <Mining> miningRows = db.Minings.ToList(); int counter = 0; foreach (var item in results) { if (miningRows.Exists(x => (x.PostalAddress_Id == ((item.Alias) + 1)))) { Mining rowUpdate = miningRows.Single(x => x.PostalAddress_Id == ((item.Alias) + 1)); rowUpdate.CityName = item.CityName; rowUpdate.Country = item.Country; rowUpdate.CountrySubentity = item.CountrySubentity; rowUpdate.PostalZone = item.PostalZone; Console.WriteLine($"Address table: {j}, {counter}"); counter++; } } db.SaveChanges(); } } }
public static void Populate() { int totalRows = Program.TotalRows; int chunkSize = Program.ChunkSize; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from b in db.Orders orderby b.ID select b).Skip(j).Take(chunkSize); //var results = query.ToList(); //for (int i = 0; i < chunkSize; i++) //{ // Mining row = new Mining // { // Order_Id = results[i].ID, // PricingCurrencyCode = results[i].PricingCurrencyCode, // TaxCurrencyCode = results[i].TaxCurrencyCode, // IssueDate = results[i].IssueDate, // AnticipatedMonetaryTotal_Id = results[i].AnticipatedMonetaryTotal_Id // }; // db.Minings.Add(row); // Console.WriteLine($"Order Table: {j}, {i}"); //} List <Mining> miningRows = db.Minings.ToList(); foreach (var item in query) { Mining rowUpdate = miningRows.Single(x => x.Order_Id == item.ID); rowUpdate.AnticipatedMonetaryTotal_Id = item.AnticipatedMonetaryTotal_Id; } db.SaveChanges(); } } }
public static void Populate() { int totalRows = Program.TotalRows; int chunkSize = Program.ChunkSize; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.LineItems join t2 in db.Minings on t1.Alias equals t2.PostalAddress_Id orderby t2.Order_Id select t1).Skip(j).Take(chunkSize); List <Mining> miningRows = db.Minings.ToList(); int counter = 0; foreach (var item in query) { //if (miningRows.Exists(x => x.PostalAddress_Id == item.Alias - 1)) //{ Mining rowUpdate = miningRows.Single(x => x.PostalAddress_Id == item.Alias - 1); rowUpdate.Quantity = item.Quantity; rowUpdate.Item_AdditionalInformation = item.Item_AdditionalInformation; rowUpdate.Item_Code = item.Item_Code; rowUpdate.Item_Type = item.Item_Type; Console.WriteLine($"LineItem table: {j}, {counter}"); counter++; //} } db.SaveChanges(); } } }
public static void Populate() { //int totalRows = Program.TotalRows; //int chunkSize = Program.ChunkSize; int totalRows = 1000000; int chunkSize = 10000; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.AllowanceCharges orderby t1.Order_Id select t1).Skip(j).Take(chunkSize); List <Mining> miningRows = db.Minings.ToList(); int counter = 0; foreach (var item in query) { if (miningRows.Exists(x => x.Order_Id == item.Order_Id)) { Mining rowUpdate = miningRows.Single(x => x.Order_Id == item.Order_Id); //rowUpdate.AllowanceChargeReason = item.AllowanceChargeReason; //rowUpdate.Amount_Value = item.Amount_Value; rowUpdate.Price_Id = item.Price_Id; Console.WriteLine($"AllowanceCharge table: {j}, {counter}"); counter++; } } db.SaveChanges(); } } }
public static void Populate() { //int totalRows = Program.TotalRows; //int chunkSize = Program.ChunkSize; int totalRows = 25000; int chunkSize = 5000; for (int j = 0; j < totalRows; j += chunkSize) { using (var db = new DM_Model()) { var query = (from t1 in db.OrderLines join t2 in db.Minings on t1.Order_Id equals t2.Order_Id orderby t2.Order_Id select t1).Skip(j).Take(chunkSize); List <Mining> miningRows = db.Minings.ToList(); int counter = 0; foreach (var item in query) { if (miningRows.Exists(x => x.Order_Id == item.Order_Id)) { Mining rowUpdate = miningRows.Single(x => x.Order_Id == item.Order_Id); rowUpdate.OrderLineAlias = item.Alias; Console.WriteLine($"OrderLine table: {j}, {counter}"); counter++; } } db.SaveChanges(); } } }