示例#1
0
        public static void SeedDatabase()
        {
            using (SupermarketDbModel mysql = new SupermarketDbModel())
            using (SupermarketDBContext sql = new SupermarketDBContext())
            {
                //sql.Database.Delete();

                foreach (var measure in mysql.Measures)
                {
                    if (!sql.Measures.Any(x=> x.MeasureId == measure.MeasureId))
                    {
                        SupermarketEF.Model.Measure measureToAdd = new SupermarketEF.Model.Measure
                        {
                            MeasureId = measure.MeasureId,
                            MeasureName = measure.MeasureName
                        };
                        sql.Measures.Add(measureToAdd);
                    }
                }

                sql.SaveChanges();

                foreach (var vendor in mysql.Vendors)
                {
                    if (!sql.Vendors.Any(x => x.VendorId == vendor.VendorId))
                    {
                        SupermarketEF.Model.Vendor vendorToAdd = new SupermarketEF.Model.Vendor
                        {
                            //Products = new HashSet<SupermarketEF.Model.Product>(),
                            VendorId = vendor.VendorId,
                            VendorName = vendor.VendorName
                        };

                        sql.Vendors.Add(vendorToAdd);
                    }

                    sql.SaveChanges();
                }

                foreach (var product in mysql.Products)
                {
                    if (!sql.Products.Any(x => x.ProductId == product.ProductId))
                    {
                        SupermarketEF.Model.Product productToAdd = new SupermarketEF.Model.Product
                        {
                            VendorId = product.VendorId,
                            ProductName = product.ProductName,
                            MeasureId = product.MeasureId,
                            BasePrice = product.BasePrice
                        };

                        sql.Products.Add(productToAdd);
                    }
                    sql.SaveChanges();
                }

            }
        }
示例#2
0
        public static void SeedDatabase()
        {
            using (SupermarketDbModel mysql = new SupermarketDbModel())
                using (SupermarketDBContext sql = new SupermarketDBContext())
                {
                    //sql.Database.Delete();

                    foreach (var measure in mysql.Measures)
                    {
                        if (!sql.Measures.Any(x => x.MeasureId == measure.MeasureId))
                        {
                            SupermarketEF.Model.Measure measureToAdd = new SupermarketEF.Model.Measure
                            {
                                MeasureId   = measure.MeasureId,
                                MeasureName = measure.MeasureName
                            };
                            sql.Measures.Add(measureToAdd);
                        }
                    }

                    sql.SaveChanges();

                    foreach (var vendor in mysql.Vendors)
                    {
                        if (!sql.Vendors.Any(x => x.VendorId == vendor.VendorId))
                        {
                            SupermarketEF.Model.Vendor vendorToAdd = new SupermarketEF.Model.Vendor
                            {
                                //Products = new HashSet<SupermarketEF.Model.Product>(),
                                VendorId   = vendor.VendorId,
                                VendorName = vendor.VendorName
                            };

                            sql.Vendors.Add(vendorToAdd);
                        }

                        sql.SaveChanges();
                    }

                    foreach (var product in mysql.Products)
                    {
                        if (!sql.Products.Any(x => x.ProductId == product.ProductId))
                        {
                            SupermarketEF.Model.Product productToAdd = new SupermarketEF.Model.Product
                            {
                                VendorId    = product.VendorId,
                                ProductName = product.ProductName,
                                MeasureId   = product.MeasureId,
                                BasePrice   = product.BasePrice
                            };

                            sql.Products.Add(productToAdd);
                        }
                        sql.SaveChanges();
                    }
                }
        }