private void CopyEmployeeTerritories(IOdb odb) { //Processing EmployeeTerritories LogMessage("Reading EmployeeTerritories...", false); var adapter1 = new EmployeeTerritoriesTableAdapter(); var table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (var row in table1) { LogMessage("EmployeeTerritories: " + row.EmployeeID.ToString() + "/" + row.TerritoryID + " ...", false); var et = new EmployeeTerritory(); LogMessage("linking members...", false); et.Employee = NDbUtil.GetByNumericalID <Employee>(odb, Employee.PK, row.EmployeeID); et.Territory = NDbUtil.GetByStringID <Territory>(odb, Territory.PK, row.TerritoryID); odb.Store(et); LogMessage("saved (" + et.Employee.EmployeeID.ToString() + "/" + et.Territory.TerritoryID + ")", true); } odb.Commit(); long objectCount = NDbUtil.GetAllInstances <EmployeeTerritory>(odb).Count; if (table1.Count == objectCount) { LogMessage(table1.Count + " objects saved", true); } else { LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); } LogMessage("Done with EmployeeTerritories" + Environment.NewLine, true); }
private void CopyCustomerCustomerDemo(IOdb odb) { //Processing CustomerCustomerDemo LogMessage("Reading CustomerCustomerDemo...", false); var adapter1 = new CustomerCustomerDemoTableAdapter(); var table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (var row in table1) { LogMessage("CustomerCustomerDemo: " + row.CustomerID + "/" + row.CustomerTypeID + " ...", false); var ccd = new CustomerCustomerDemo(); LogMessage("linking members...", false); ccd.CustomerID = NDbUtil.GetByStringID <Customer>(odb, Customer.PK, row.CustomerID); ccd.CustomerTypeID = NDbUtil.GetByStringID <CustomerDemographics>(odb, CustomerDemographics.PK, row.CustomerTypeID); odb.Store(ccd); LogMessage("saved (" + ccd.CustomerID.CustomerID + "/" + ccd.CustomerTypeID.CustomerTypeID + ")", true); } odb.Commit(); long objectCount = NDbUtil.GetAllInstances <CustomerCustomerDemo>(odb).Count; if (table1.Count == objectCount) { LogMessage(table1.Count + " objects saved", true); } else { LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); } LogMessage("Done with CustomerCustomerDemo" + Environment.NewLine, true); }
private void CopyOrders(IOdb odb, ref double progress) { var orders = new List <Order>(); var customers = new Hashtable(); var employees = new Hashtable(); var shippers = new Hashtable(); //Processing Orders LogMessage("Reading Orders...", false); var adapter1 = new OrdersTableAdapter(); var table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (var row in table1) { var o = new Order { OrderID = row.OrderID, Freight = row.IsFreightNull() ? 0 : Convert.ToDouble(row.Freight), ShipName = row.IsShipNameNull() ? null : row.ShipName, ShipAddress = row.IsShipAddressNull() ? null : row.ShipAddress, ShipCity = row.IsShipCityNull() ? null : row.ShipCity, ShipRegion = row.IsShipRegionNull() ? null : row.ShipRegion, ShipPostalCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode, ShipCountry = row.IsShipCountryNull() ? null : row.ShipCountry }; if (!row.IsCustomerIDNull()) { customers.Add(o.OrderID, row.CustomerID); } if (!row.IsEmployeeIDNull()) { employees.Add(o.OrderID, row.EmployeeID); } if (!row.IsShipViaNull()) { shippers.Add(o.OrderID, row.ShipVia); } if (!row.IsOrderDateNull()) { o.OrderDate = row.OrderDate; } if (!row.IsRequiredDateNull()) { o.RequiredDate = row.RequiredDate; } if (!row.IsShippedDateNull()) { o.ShippedDate = row.ShippedDate; } orders.Add(o); } foreach (var o in orders) { LogMessage("Order: " + o.OrderID.ToString() + " ...", false); if (customers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var customerID = Convert.ToString(customers[o.OrderID]); var found = NDbUtil.GetByStringID <Customer>(odb, Customer.PK, customerID); o.Customer = found; } if (employees.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var employeeID = Convert.ToInt64(employees[o.OrderID]); var found = NDbUtil.GetByNumericalID <Employee>(odb, Employee.PK, employeeID); o.Employee = found; } if (shippers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var shipperID = Convert.ToInt64(shippers[o.OrderID]); var found = NDbUtil.GetByNumericalID <Shipper>(odb, Shipper.PK, shipperID); o.ShipVia = found; } odb.Store(o); StepFinished(progress += 0.029); LogMessage("saved (" + o.OrderID.ToString() + ")", true); } odb.Commit(); LogMessage("Commit done, starting create index ...", false); odb.IndexManagerFor <Order>().AddUniqueIndexOn("Order_OrderID_PK_index", Order.PK); odb.Commit(); LogMessage(" index created.", true); long objectCount = NDbUtil.GetAllInstances <Order>(odb).Count; if (table1.Count == objectCount) { LogMessage(table1.Count + " objects saved", true); } else { LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); } LogMessage("Done with Orders" + Environment.NewLine, true); }