Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var customers = new ShopDB.CustomersDataTable();

            var customersTableAdapter = new CustomersTableAdapter();

            customersTableAdapter.ClearBeforeFill = true;
            customersTableAdapter.Insert("test", "test", "test", "test", "test", "test", "test", new DateTime(9999 / 12 / 31));
            //var insertedRowNumber = customersTableAdapter.Insert("test", "test", "test", "test", "test", "test", "test", new DateTime(9999 / 12 / 31));

            customers = customersTableAdapter.GetData();

            DataRow[] testRows = customers.Select("Phone='test'");

            foreach (DataRow testRow in testRows)
            {
                foreach (DataColumn column in customers.Columns)
                {
                    Console.WriteLine($"{column.ColumnName}: {testRow[column]}");
                }
                Console.WriteLine();
            }

            //now we're going to delete rows with test phone numbers
            Console.WriteLine(new string('*', 30));
            Console.WriteLine($"Total test row(s) deleted: {DeleteTestRows()}");
            //customersTableAdapter.Delete(insertedRowNumber); //doesn't work with sole int
            customers = customersTableAdapter.GetData();
            testRows  = customers.Select("Phone = 'test'");

            foreach (DataRow testRow in testRows)
            {
                foreach (DataColumn column in customers.Columns)
                {
                    Console.WriteLine($"{column.ColumnName}: {testRow[column]}");
                }
            }

            Console.ReadKey();
        }
        private void CopyCustomers(IOdb odb)
        {
            //Processing Customers
            LogMessage("Reading Customers...", false);
            var adapter1 = new CustomersTableAdapter();
            var table1   = adapter1.GetData();

            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                LogMessage("Customer: " + row.CustomerID + " ...", false);

                var c = new Customer
                {
                    CustomerID   = row.CustomerID,
                    CompanyName  = row.CompanyName,
                    ContactName  = row.IsContactNameNull() ? null : row.ContactName,
                    ContactTitle = row.IsContactTitleNull() ? null : row.ContactTitle,
                    Address      = row.IsAddressNull() ? null : row.Address,
                    City         = row.IsCityNull() ? null : row.City,
                    Region       = row.IsRegionNull() ? null : row.Region,
                    PostalCode   = row.IsPostalCodeNull() ? null : row.PostalCode,
                    Country      = row.IsCountryNull() ? null : row.Country,
                    Phone        = row.IsPhoneNull() ? null : row.Phone,
                    Fax          = row.IsFaxNull() ? null : row.Fax
                };

                odb.Store(c);
                LogMessage("saved", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor <Customer>().AddUniqueIndexOn("Customer_CustomerID_PK_index", Customer.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances <Customer>(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 Customers" + Environment.NewLine, true);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var customersTableAdapter = new CustomersTableAdapter();
            var customers             = customersTableAdapter.GetData(); //creates a customersdatatable

            foreach (DataRow row in customers.Rows)
            {
                foreach (DataColumn column in customers.Columns)
                {
                    Console.WriteLine($"{column.ColumnName}: {row[column]}");
                }
                Console.WriteLine();
            }

            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void CopyCustomers()
        {
            //Processing Customers
            LogMessage("Reading Customers...", false);
            CustomersTableAdapter adapter1 = new CustomersTableAdapter();
            NorthwindDb4o.NorthwindDataSet.CustomersDataTable table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (NorthwindDb4o.NorthwindDataSet.CustomersRow row in table1)
            {
                LogMessage("Customer: " + row.CustomerID.ToString() + " ...", false);

                Customer c = new Customer();

                c.CustomerID = row.CustomerID;
                c.CompanyName = row.CompanyName;
                c.ContactName = row.IsContactNameNull() ? null : row.ContactName;
                c.ContactTitle = row.IsContactTitleNull() ? null : row.ContactTitle;
                c.Address = row.IsAddressNull() ? null : row.Address;
                c.City = row.IsCityNull() ? null : row.City;
                c.Region = row.IsRegionNull() ? null : row.Region;
                c.PostalCode = row.IsPostalCodeNull() ? null : row.PostalCode;
                c.Country = row.IsCountryNull() ? null : row.Country;
                c.Phone = row.IsPhoneNull() ? null : row.Phone;
                c.Fax = row.IsFaxNull() ? null : row.Fax;

                container.Store(c);
                LogMessage("saved", true);
            }
            container.Commit();
            long objectCount = Db4oUtil.GetAllInstances(container, typeof(Customer)).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 Customers" + Environment.NewLine, true);
        }
Exemplo n.º 5
0
        private void CopyCustomers(IOdb odb)
        {
            //Processing Customers
            LogMessage("Reading Customers...", false);
            var adapter1 = new CustomersTableAdapter();
            var table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                LogMessage("Customer: " + row.CustomerID + " ...", false);

                var c = new Customer
                            {
                                CustomerID = row.CustomerID,
                                CompanyName = row.CompanyName,
                                ContactName = row.IsContactNameNull() ? null : row.ContactName,
                                ContactTitle = row.IsContactTitleNull() ? null : row.ContactTitle,
                                Address = row.IsAddressNull() ? null : row.Address,
                                City = row.IsCityNull() ? null : row.City,
                                Region = row.IsRegionNull() ? null : row.Region,
                                PostalCode = row.IsPostalCodeNull() ? null : row.PostalCode,
                                Country = row.IsCountryNull() ? null : row.Country,
                                Phone = row.IsPhoneNull() ? null : row.Phone,
                                Fax = row.IsFaxNull() ? null : row.Fax
                            };

                odb.Store(c);
                LogMessage("saved", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor<Customer>().AddUniqueIndexOn("Customer_CustomerID_PK_index", Customer.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances<Customer>(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 Customers" + Environment.NewLine, true);
        }