private static Categoria Mapping(Category category)
 {
     Categoria categoria = new Categoria();
     categoria.CategoryID = category.CategoryID;
     categoria.CategoryName = category.CategoryName;
     return categoria;
 }
 private TreeNode GetTreeNodes(Category category)
 {
     TreeNode result = new TreeNode();
     result.Text = category.Name;
     result.Tag = category.Id;
     foreach (Category child in category.Children)
     {
         result.Nodes.Add(GetTreeNodes(child));
     }
     return result;
 }
 private void button1_Click(object sender, EventArgs e)
 {
     string name = textBox2.Text;
     if (string.IsNullOrEmpty(name))
         return;
     using (DataContainer c = new DataContainer())
     {
         int id = Convert.ToInt32(Tree1.SelectedNode.Tag);
         Category parent = c.Category.First(p => p.Id == id);
         Category category = new Category();
         category.Name = name;
         category.Parent = parent;
         c.AddToCategory(category);
         c.SaveChanges();
     }
     //LoadInfo();
 }
        private void LoadInfo()
        {
            using (DataContainer c = new DataContainer())
            {
                var allCategorys = c.Category.ToList();

                if (allCategorys.Count == 0 || allCategorys.Any(p => p.Name == "root") == false)
                {
                    Category root_add = new Category();
                    root_add.Name = "root";
                    root_add.Parent = null;
                    c.AddToCategory(root_add);
                    c.SaveChanges();
                }

                Category root = c.Category.Where(p => p.Name == "root").First();
                Tree1.Nodes.Clear();
                var nodes = GetTreeNodes(root);
                nodes.ExpandAll();
                Tree1.Nodes.Add(nodes);

            }
        }
        private static void CreateCategory(
            IDataContext dataContext,
            DefaultCategory defaultCategory,
            User user)
        {
            var category = new Category
            {
                Title = defaultCategory.Title,
                Type = defaultCategory.Type,
                User = user
            };

            dataContext.Categories.Add(category);
        }
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Category CreateCategory(global::System.Int32 id, global::System.String name)
 {
     Category category = new Category();
     category.Id = id;
     category.Name = name;
     return category;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Category EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategory(Category category)
 {
     base.AddObject("Category", category);
 }