【发布时间】:2020-05-25 17:54:03
【问题描述】:
在博客页面上, 子类别将链接到主类别,并且将是子类别的文章。你觉得模型结构正确吗?
我将使用 Asp.net Core 和 EntityFrameworkCore 架构进行开发。
public class Category
{
public int Id { get; set; }
public string CategoryName { get; set; }
public bool IsActive { get; set; }
public ICollection<SubCategory> SubCategories { get; set; }
}
--------------------------------------
public class SubCategory
{
public int Id { get; set; }
public string SubCategoryName { get; set; }
public bool IsActive { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Article> Articles { get; set; }
}
----------------------------------------------
public class Article
{
public int Id { get; set;}
public string ArticleTitle { get; set; }
public string ArticleContent { get; set; }
public DateTime PublishDate { get; set; }
public int AuthorId { get; set; }
public virtual Author Author { get; set; }
public int SubCategoryId { get; set; }
public virtual SubCategory SubCategory { get; set; }
}
【问题讨论】:
标签: c# entity-framework asp.net-core model tree