I have an entity with a Property called ParentId linked to an navigation property called Parent. This relationship seems to be working fine but my issue is now i want to have another navigation property which would be a list of "Child" items where the parent is the same as the entities ID.
I have Tried "ID", "Parent" in my FK attribute but i get the "The ForeignKeyAttribute on property 'Children' on type 'jrSite.Core.SiteModel' is not valid" error.
How do i tell EF that i want that navigation property to search the SiteModel table for items with matching parent id?
My class is below
public class SiteModel
{
public SiteModel() { }
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public DateTime Created { get; set; }
[ForeignKey("Creator")]
public int CreatorID;
public SiteAccount Creator { get; set; }
[ForeignKey("Owner")]
public int OwnerID;
public SiteAccount Owner { get; set; }
[ForeignKey("Parent")]
public int? ParentID;
public SiteModel Parent { get; set; }
[ForeignKey("Parent")]
public List<SiteModel> Children { get; set; }
public SiteModel(SiteAccount creator, SiteAccount owner)
{
Creator = creator;
Owner = owner;
Created = DateTime.Now;
}
}
public SiteModel() { }. It's by default anyway. - Yair Nevet