我想我找到了答案,如果我错了,有人纠正我:
public class HtmlElement : DelEntity
{
// Primitives
public virtual string DisplayName { get; set; }
// Foreign Key
public virtual long? ParentElementId { get; set; } // If it is a child
//Navigation - Class
[ForeignKey("ParentElementId")]
public virtual HtmlElement ParentHtmlElement { get; set; }
//Navigation - Collections (if it is a parent)
private ICollection<HtmlElement> _childElements;
[InverseProperty("ParentHtmlElement")]
public virtual ICollection<HtmlElement> ChildElements
{
get { return _childElements ?? (_childElements = new HashSet<HtmlElement>()); }
set { _childElements = value; }
}
}