0

我在这些电话中遇到了这些错误。我一定做错了什么:-)但是在哪里?

在我的控制器上,我有这个:

var faqs = _context.Faqs.Include(c=>c.Categories).ThenInclude(c=>c.category);

var forums = _context.Forums.Include(c => c.Categories).ThenInclude(c => c.category);

错误:

Additional information: Invalid column name 'FaqId'.

Additional information: Invalid column name 'ForumId'.

代码:

public class Category
{
    [Key]
    public string Id { get; set; } = Guid.NewGuid().ToString();

    [Required()]
    public string Name { get; set; }

    [Required()]
    public Int64 ApplyTo { get; set; }=0;

    [Required()]
    public Int64 EnumNumber { get; set; } = 0; 
}

public class CategoryObject 
{
    [Key]
    public string Id { get; set; } = Guid.NewGuid().ToString();

    /// <summary>
    /// Refers to class object like FAQs, Forum
    /// </summary>        
    public string ObjectId { get; set; }

    public virtual Category category { get; set; }
    public string CategoryId { get; set; } 
}

public class Faq
{
    [Key]
    public string Id { get; set; } = Guid.NewGuid().ToString(); 

    [Required()]
    public string Name { get; set; }         
    [Required()]
    public string Answer { get; set; }

    /// <summary>
    /// List of all categories this FAQ belongs
    /// </summary>
    public virtual ICollection<CategoryObject> Categories { get; set; } 
}

public class Forum
{
    [Key]
    public string Id { get; set; } = Guid.NewGuid().ToString();         

    [Required()]
    public override string Name { get; set; }

    public string Description { get; set; } = "";

    /// <summary>
    /// List of all categories this Forum belongs
    /// </summary>
    public virtual ICollection<CategoryObject> Categories { get; set; }
}

所有的想法是我有一个标记有一些类别的对象,并且想要提取该对象具有的所有类别。在这种情况下,FAQ 和 Forum 以及其他可能会有一些分类。可能有更好的方法?也接受建议。

谢谢

4

0 回答 0