我有一个像
这样的域类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>();
}
}
在生成的代码中,我找到了products集合,但没有找到子集合。使用同一个课程有一些限制吗?还有另一种方法可以建模这种关系,而不需要重复使用密钥吗?
答案 0 :(得分:0)
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>();
}
}