static void Print(PictureCategory cat, int level) { StringBuilder sb = new StringBuilder(); Console.WriteLine("{0}{1}", sb.Append(' ', level).ToString(), cat.Name); foreach (PictureCategory child in cat.Subcategories) { Print(child, level + 1); } }
/// <summary> /// Create a new PictureCategory object. /// </summary> /// <param name="categoryId">Initial value of the CategoryId property.</param> /// <param name="name">Initial value of the Name property.</param> public static PictureCategory CreatePictureCategory(global::System.Int32 categoryId, global::System.String name) { PictureCategory pictureCategory = new PictureCategory(); pictureCategory.CategoryId = categoryId; pictureCategory.Name = name; return(pictureCategory); }
static void RunExample() { using (var context = new EFRecipesEntities()) { 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); context.PictureCategories.AddObject(paris); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { context.ContextOptions.LazyLoadingEnabled = true; PictureCategory root = (from c in context.PictureCategories where c.ParentCategory == null select c).FirstOrDefault(); Print(root, 0); } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }
/// <summary> /// Deprecated Method for adding a new object to the PictureCategories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPictureCategories(PictureCategory pictureCategory) { base.AddObject("PictureCategories", pictureCategory); }