I'm building a hierarchical Database with "closure table" to build the tree It is a self referencing table, and the two keys should become the primary key.
The Problem is, I end up with 5 columns, when I expect only 3.
Here is what I tried:
public class Tree
{
public int TaskId { get; set; }
public Task Task { get; set; } //navigation Property to TaskTable
public int? ChildId { get; set; }
public Tree Child { get; set; } //navigation Property
public int Length { get; set; } //Length
}
public class Task
{
public int TaskId { get; set; }
public virtual ICollection<Tree> Trees { get; set; }
}
modelBuilder
.Entity<Task>()
.HasKey(t => t.TaskId);
modelBuilder
.Entity<Tree>()
.HasKey(a => new { a.TaskId, a.ChildId });
The result is a table with 5 columns:
- TaskId
- ChildId
- Length
- Child_TaskId
- Child_ChildId
I expected:
- TaskId
- ChildId
- Length
I'm guessing some fluent api missing, but I couldn't get to work otherwise ?