Ejemplo n.º 1
0
        static void Print(PictureCategory cat, int level)
        {
            StringBuilder sb = new StringBuilder();

            Console.WriteLine("{0}{1}", sb.Append(' ', level).ToString(), cat.Name);

            cat.Subcategories.ForEach(child => Print(child, level + 1));
        }
Ejemplo n.º 2
0
        private static void AddData5()
        {
            using (var ctx = new EFRecipesEntities5())
            {
                var louvre = new PictureCategory {
                    Name = "Louvre"
                };
                var child = new PictureCategory {
                    Name = "Egyptian Antiquites"
                };
                louvre.Subcategories.Add(child);
                child = new PictureCategory {
                    Name = "Sculptures"
                };
                louvre.Subcategories.Add(child);
                child = new PictureCategory {
                    Name = "Paintings"
                };
                louvre.Subcategories.Add(child);
                var paris = new PictureCategory {
                    Name = "Paris"
                };
                paris.Subcategories.Add(louvre);
                var vacation = new PictureCategory {
                    Name = "Summer Vacation"
                };
                vacation.Subcategories.Add(paris);
                ctx.PictureCategories.Add(paris);
                ctx.SaveChanges();

                /*
                 * PictureCategory pc1 = new PictureCategory() { Name = "L1a" };
                 * PictureCategory pc2 = new PictureCategory() { Name = "L1b" };
                 * PictureCategory pc3 = new PictureCategory() { Name = "L1c" };
                 * PictureCategory pc4 = new PictureCategory() { Name = "L1d" };
                 * pc4.Subcategories.Add(new PictureCategory { Name = "L2a" });
                 * pc4.Subcategories.Add(new PictureCategory { Name = "L2b" });
                 * PictureCategory pc = new PictureCategory() { Name = "L" };// Subcategories = new List<PictureCategory> { pc1, pc2, pc3, pc4 } };
                 * pc.Subcategories.Add(pc1);
                 * pc.Subcategories.Add(pc2);
                 * pc.Subcategories.Add(pc3);
                 * ctx.PictureCategories.Add(pc);
                 * ctx.SaveChanges();*/
            }
        }