我有一个员工等级制度,有老板和下属。
public class Employee
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string Job { get; set; }
public virtual Employee Boss { get; set; }
public virtual ICollection<Employee> Subordinates { get; set; }
}
我尝试将其配置如下:
internal class EmployeeConfiguracao : EntityTypeConfiguration<Employee>
{
public EmployeeConfiguracao()
{
HasOptional(p => p.Boss).WithMany(p => p.Subordinates).WillCascadeOnDelete(false);
}
}
但是Add-Migration Init
Note that Boss is not-null but the is optional (总统没有老板)的结果
CreateTable(
"dbo.Employees",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(nullable: false, maxLength: 90),
Job = c.String(),
Boss_Id = c.Int(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Employees", t => t.Boss_Id)
.Index(t => t.Boss_Id);
如何建立这种层次结构,使其可以在没有老板(作为总裁)的情况下使用