开发者

Child objects in domain class

开发者 https://www.devze.com 2023-03-13 11:58 出处:网络
I have a domain class like public class Category { [Key] public string IdCategory { get; set; } public string Name { get; set; }

I have a domain class like

public class Category
{
    [Key]
    public string IdCategory { get; set; }
    public string Name { get; set; }
    public List<Category> Children { get; set; }
    public List<Product> Products { 开发者_Python百科get; set; }



    public Category()
    {
        Products = new List<Product>();
        Children = new List<Category>();
    }

}

In the generated code I find the products collection, but not the children collection. There are some restriction about using the same class? There is another way to modeling this relation without recurring to keys?


public  class Category
    {
        [Key]
        public string IdCategory { get; set; }
        public string Name { get; set; }
        public string IdFather { get; set; }
        public List<Product> Products { get; set; }
        [Include]            
        [Association("ParentChild", "IdCategory", "IdFather")]
        public List<Category> Children { get; set; }




        public Category()
        {
            Products = new List<Product>();
            Children = new List<Category>();

        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消