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 { 开发者_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>();
}
}
精彩评论