I know the problem: I am missing a mapping to help EF understand the relationship between my two tables but I am not seeing where my mistake is.
I have a Web Api using EF CF 7. I can query fine and get the parent table data but when I try to include the related child data I am getting the invalid column error.
My two tables look like this:
public class Categories { private ICollection<SubCategories> _subcat; public int Id { get; set; } public string Category { get; set; } public virtual ICollection<SubCategories> SubCategories { get { return _subcat ?? (_subcat = new List<SubCategories>()); } set { _subcat = value; } } } public class SubCategories { public int Id { get; set; } public string SubCategory { get; set; } } The above classes match my db schema EXCEPT the SubCategories table has a column CategoryId and it is a FK to the parent table Id column.
My repository query looks like this:
return _context.Categories.Include(i => i.SubCategories).ToList(); Now the error is throwing me...and I vaguely remember it has to do with EF concatenating the name. In that experience there was a base class that had the Id defined therefore when I defined it in my class it conflicted but that isn't the case here?
Invalid column name 'CategoriesId'.
So I have google and read several articles but either I didn't understand completely or they weren't my problem - probably the former.