Search code examples
wcf-ria-services

Child objects in domain class


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 { 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?


Solution

  • 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>();
    
            }
        }