Пример #1
0
        private static void ExportCustomerFromMSSqlToMySQL()
        {
            var mssqlClients = new GenericRepository<Customer>(new GirlsAgencyContext());
            var girlsMySql = new GenericRepository<Girl>(new GirlAgencyMySql.Data.MySql());
            var mysqlClients = new GenericRepository<Customer>(new GirlAgencyMySql.Data.MySql());
            foreach (var mssqlCustomer in mssqlClients.GetAll().ToList())
            {
                var customer = new Customer()
                {
                    CityId = mssqlCustomer.CityId,
                    CountryId = mssqlCustomer.CountryId,
                    FirstName = mssqlCustomer.FirstName,
                    LastName = mssqlCustomer.LastName,
                    Girls = GetGirls(mssqlCustomer, girlsMySql)
                };

                mysqlClients.Add(customer);
            }

            mysqlClients.SaveChanges();
        }
Пример #2
0
        private static ICollection<Girl> GetGirls(Customer mssqlCustomer, GenericRepository<Girl> girlsMySql)
        {
            var girls = new List<Girl>();
            foreach (var girl in mssqlCustomer.Girls)
            {
                var girlInDb = girlsMySql
                    .GetAll()
                    .Where(n => n.FirstName == girl.FirstName && n.LastName == girl.LastName)
                    .FirstOrDefault();

                girls.Add(girlInDb);
            }

            return girls;
        }
Пример #3
0
        private static IEnumerable GetCustomer(object[,] array)
        {
            var customerArray = new List<Customer>();

            for (var row = 2; row <= array.GetLength(0); row++)
            {
                var girl = new Customer
                {
                    FirstName = array[row, 1].ToString(),
                    LastName = array[row, 2].ToString(),
                    CityId = Convert.ToInt32(array[row, 3]),
                    CountryId = Convert.ToInt32(array[row, 4])
                };

                customerArray.Add(girl);
            }

            return customerArray;
        }