I get : ERROR: Invalid column name 'OrganizationStructure_ID'.
public OrganizationStructure() { ChildrenItems = new HashSet<OrganizationStructure>(); InputDate = DateTime.Now; } public int ID { get; set; } public string Name { get; set; } public virtual int? ParentID { get; set; } public int OrganizationID { get; set; } public int OrganizationTypeID { get; set; } public int OrganizationActivityID { get; set; } public int OrganizationLocationID { get; set; } public string AddRemark { get; set; } public int UserId { get; set; } public DateTime InputDate { get; set; } public int? RemAttr { get; set; } public virtual ICollection<OrganizationStructure> ChildrenItems { get; set; }
INDEX ACTION:
return View(_organizationStructureRepository.GetAll().ToList() .Where(t => t.ParentID == null));
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With