Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     using (var context = new Core.DAL.EasyScheduleDatabaseEntities())
     {
         var products = context.Products;
         context.Categories.Load();
         foreach (var product in products)
         {
             product.FullName = product.Name + " [ " + product.Category.Name + " ]";
         }
         context.SaveChanges();
     }
     // Console.ReadKey();
 }
Ejemplo n.º 2
0
        //static void LoadDatabase()
        //{
        //    using (var context = new SecretDatabaseEntities())
        //    {
        //        foodFinder.Products = new List<ProductLink>();
        //        foodFinder.Categories = context.Categories.Include("ProductLinks").ToList();
        //        foreach (var category in foodFinder.Categories)
        //        {
        //            foreach (var product in category.ProductLinks)
        //            {
        //                product.Category = category;
        //            }
        //            foodFinder.Products.AddRange(category.ProductLinks);
        //        }
        //    }
        //}

        //static void LoadCategories()
        //{
        //    Console.Write("Fetching categories...");
        //    start = DateTime.Now;
        //    foodFinder.FetchFoodCategories();
        //    end = DateTime.Now;
        //    Console.WriteLine(" {0} ms\n", (end - start).TotalMilliseconds);
        //    Console.WriteLine("{0} categories fetched:", foodFinder.Categories.Count);
        //    foreach (var category in foodFinder.Categories)
        //    {
        //        Console.WriteLine("- {0}", category.Name);
        //    }
        //    Console.WriteLine("\n");
        //    using (var context = new SecretDatabaseEntities())
        //    {
        //        foreach (var category in foodFinder.Categories)
        //        {
        //            context.Categories.Add(new Category
        //                                       {
        //                                           CategoryTypeId = 1,
        //                                           Link = category.Link,
        //                                           Name = category.Name
        //                                       });
        //        }
        //        context.SaveChanges();
        //    }
        //}

        //static void LoadBrands()
        //{
        //    start = DateTime.Now;
        //    var brands = foodFinder.FetchBrands(2).ToList();
        //    end = DateTime.Now;
        //    Console.WriteLine(" {0} ms\n", (end - start).TotalMilliseconds);
        //    Console.WriteLine("{0} brands fetched:", brands.Count);
        //    Console.WriteLine("\n");
        //    using (var context = new SecretDatabaseEntities())
        //    {
        //        foreach (var category in brands)
        //        {
        //            context.Categories.Add(category);
        //        }
        //        context.SaveChanges();

        //        Console.WriteLine("{0} rows were written to database", brands.Count);
        //    }
        //}

        //static void LoadRestaurants()
        //{
        //    start = DateTime.Now;
        //    var brands = foodFinder.FetchBrands(3).ToList();
        //    end = DateTime.Now;
        //    Console.WriteLine(" {0} ms\n", (end - start).TotalMilliseconds);
        //    Console.WriteLine("{0} brands fetched:", brands.Count);
        //    Console.WriteLine("\n");
        //    using (var context = new SecretDatabaseEntities())
        //    {
        //        foreach (var category in brands)
        //        {
        //            context.Categories.Add(category);
        //        }
        //        context.SaveChanges();

        //        Console.WriteLine("{0} rows were written to database", brands.Count);
        //    }
        //}

        //static void LoadSupermarkets()
        //{
        //    start = DateTime.Now;
        //    var brands = foodFinder.FetchBrands(4).ToList();
        //    end = DateTime.Now;
        //    Console.WriteLine(" {0} ms\n", (end - start).TotalMilliseconds);
        //    Console.WriteLine("{0} brands fetched:", brands.Count);
        //    Console.WriteLine("\n");
        //    using (var context = new SecretDatabaseEntities())
        //    {
        //        foreach (var category in brands)
        //        {
        //            context.Categories.Add(category);
        //        }
        //        context.SaveChanges();

        //        Console.WriteLine("{0} rows were written to database", brands.Count);
        //    }
        //}

        //static void LoadCategoryProducts()
        //{

        //    foreach (var category in foodFinder.Categories)
        //    {
        //        Console.WriteLine("Go to {0} category", category.Name);
        //        Console.WriteLine("Fetching products list...");
        //        start = DateTime.Now;
        //        var list = foodFinder.FetchCategoryProducts(category);
        //        end = DateTime.Now;
        //        Console.WriteLine(" {0} ms\n", (end - start).TotalMilliseconds);
        //        Console.WriteLine("{0} products fetched", list.Count());
        //        using (var context = new SecretDatabaseEntities())
        //        {
        //            foreach (var product in category.ProductLinks.Where(p => p.Id < 1))
        //            {
        //                context.ProductLinks.Add(new ProductLink
        //                {
        //                    Name = product.Name,
        //                    CategoryId = product.Category.Id,
        //                    Link = product.Link
        //                });
        //            }
        //            context.SaveChanges();
        //            Console.WriteLine("{0} rows were written to database");
        //        }
        //    }

        //}

        static void TransferCategories()
        {
            var secretContext   = new Secret.SecretDatabaseEntities();
            var scheduleContext = new Core.DAL.EasyScheduleDatabaseEntities();

            foreach (var category in secretContext.Categories)
            {
                scheduleContext.Categories.Add(new Core.DAL.Category
                {
                    Id             = category.Id,
                    Name           = category.Name,
                    CategoryTypeId = category.CategoryTypeId
                });
                scheduleContext.SaveChanges();
            }
            secretContext.Dispose();
            scheduleContext.Dispose();
        }