When using the CTP 5 of Entity Framework code-first library (as announced here) I\'m trying to create a class that maps to a very simple hierarchy table.
Here\'s the SQL
In Entity Framework 6 you can do it like this, note public Guid? ParentId { get; set; }
. The foreign key MUST be nullable for it to work.
class Person
{
public Guid Id { get; set; }
public string Name { get; set; }
public Guid? ParentId { get; set; }
public virtual Person Parent { get; set; }
public virtual ICollection Children { get; set; }
}
https://stackoverflow.com/a/5668835/3850405