我有 3 个模型:
- 模型 1:
文章
- 模型 2:
类(class)
- 模型 3:
剧集
他们都可以有很多评论。
如何在这些和 Comment
模型之间建立关系?
最佳答案
假设您的文章、类(class)和剧集中的 Id 类型为 long
,在 Comment 模型中,您可以有这样的内容
public class Comment
{
public long CommentId { get; set; }
public string Message { get; set; }
public DateTime EntryDate { get; set; }
//Type to store Article, Course or Episode
public string Type { get; set; }
//TypeId to store the Id of the Article, Course or Episode
public long TypeId { get; set; }
}
您还可以更改 public string Type { get;放; }
到枚举中以更加清晰易懂。
关于asp.net - Asp.net Core中多个模型与注释模型的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62488457/