Mapping for self referencing entity in EF Code First
In my database I have a table Category, with columns Id, CategoryName, ParentCategoryId, where ParentCategoryId has a constraint on Category.Id. I'm using entity framework code first, where the entity looks like: public class Category { public long Id { get; private set; } public string CategoryName { get; private set; } public long? ParentCategoryId { get; private set; } public Category ParentCategory { get; private set; } public virtual ICollection<Category> SubCategories { get; private set; } } If I try to run a query against this, I get the exception: The relationship 'ComplaintModel.FK