asp.net - Asp.net Core中多个模型与注释模型的关系

标签 asp.net entity-framework asp.net-core

我有 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/

相关文章:

c# - 如何遍历控件以获得特定类型的控件?

c# - 代表经过身份验证的 SAML 用户发出 asmx 请求

c# - Entity Framework 6 尝试在重命名时删除不存在的索引

javascript - NavigateUrl 和 EVAL

c# - 使用 download.aspx 时加载图像缓慢

asp.net-mvc-3 - 达到相关实体的属性

c# - 尽管未调用complete(),TransactionScope 仍不回滚

c# - ASP.NET Core - 向用户添加角色声明

c# - ASP.NET Core 3.1 Web 应用程序在 IIS Express 上运行时抛出错误 500.30,但在使用 dotnet watch run 时不会抛出错误

asp.net-core - 如何使用.net core更改ubuntu操作系统中的系统日期时间