Exemplo n.º 1
0
        public static void MigrateDataFromMySqlToMSSql()
        {
            using (SupermarketMySqlEntities mySqlDb = new SupermarketMySqlEntities())
            {
                using (SupermarketReportsEntities msSqlDb = new SupermarketReportsEntities())
                {
                    var vendors = mySqlDb.Vendors;
                    foreach (var vendor in vendors)
                    {
                        SupermarketMSSql.Model.Vendor newVendor = new SupermarketMSSql.Model.Vendor
                        {
                            VendorName = vendor.VendorName
                        };

                        msSqlDb.Vendors.Add(newVendor);
                    }

                    msSqlDb.SaveChanges();
                    var measures = mySqlDb.Measures;
                    foreach (var measure in measures)
                    {
                        SupermarketMSSql.Model.Measure newMeasure = new SupermarketMSSql.Model.Measure
                        {
                            MeasureName = measure.MeasureName
                        };

                        msSqlDb.Measures.Add(newMeasure);
                    }

                    msSqlDb.SaveChanges();

                    var products = mySqlDb.Products;
                    foreach (var product in products)
                    {
                        var vendor = msSqlDb.Vendors.Where(v => v.VendorName == product.Vendor.VendorName).First();
                        var measure = msSqlDb.Measures.Where(m => m.MeasureName == product.Measure.MeasureName).First();
                        SupermarketMSSql.Model.Product newProduct = new SupermarketMSSql.Model.Product
                        {
                            ProductName = product.ProductName,
                            BasePrice = product.BasePrice,
                            Measures_MeasureId = measure.MeasureId,
                            Vendors_VendorId = vendor.VendorId
                        };

                        msSqlDb.Products.Add(newProduct);
                    }

                    msSqlDb.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public static void MigrateDataFromMySqlToMSSql()
        {
            using (SupermarketMySqlEntities mySqlDb = new SupermarketMySqlEntities())
            {
                using (SupermarketReportsEntities msSqlDb = new SupermarketReportsEntities())
                {
                    var vendors = mySqlDb.Vendors;
                    foreach (var vendor in vendors)
                    {
                        SupermarketMSSql.Model.Vendor newVendor = new SupermarketMSSql.Model.Vendor
                        {
                            VendorName = vendor.VendorName
                        };

                        msSqlDb.Vendors.Add(newVendor);
                    }

                    msSqlDb.SaveChanges();
                    var measures = mySqlDb.Measures;
                    foreach (var measure in measures)
                    {
                        SupermarketMSSql.Model.Measure newMeasure = new SupermarketMSSql.Model.Measure
                        {
                            MeasureName = measure.MeasureName
                        };

                        msSqlDb.Measures.Add(newMeasure);
                    }

                    msSqlDb.SaveChanges();

                    var products = mySqlDb.Products;
                    foreach (var product in products)
                    {
                        var vendor  = msSqlDb.Vendors.Where(v => v.VendorName == product.Vendor.VendorName).First();
                        var measure = msSqlDb.Measures.Where(m => m.MeasureName == product.Measure.MeasureName).First();
                        SupermarketMSSql.Model.Product newProduct = new SupermarketMSSql.Model.Product
                        {
                            ProductName        = product.ProductName,
                            BasePrice          = product.BasePrice,
                            Measures_MeasureId = measure.MeasureId,
                            Vendors_VendorId   = vendor.VendorId
                        };

                        msSqlDb.Products.Add(newProduct);
                    }

                    msSqlDb.SaveChanges();
                }
            }
        }