That is because you didn’t pair your FK property with a navigation property. I expect the ParentID
should point to parent OrganizationStructure
and ChildrenItems
should point to children OranizationStructures
.
If your model doesn’t contain Parent
navigation property to parent OrganizationStructure
you must use fluent-API to tell EF that ParentID
is FK:
modelBuilder.Entity<OrganizationStructure>()
.HasMany(o => o.ChildrenItems)
.WithOptional()
.HasForeignKey(c => c.ParentID);