I got these error on those calls. I must be doing something wrong :-) but where?
On my controller I have this:
var faqs = _context.Faqs.Include(c=>c.Categories).ThenInclude(c=>c.category);
var forums = _context.Forums.Include(c => c.Categories).ThenInclude(c => c.category);
Errors:
Additional information: Invalid column name 'FaqId'.
Additional information: Invalid column name 'ForumId'.
Code:
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; }
}
The all idea is that I have an object flagged with some categories and would like to pull all the categories that the object has. In this case, FAQ and Forum plus others could have some categorization. There might be a better way? Open to suggestions as well.
Thanks