Base solution for your next web application
Open Closed

Extend OrganizationUnit and not functioning IRepository #5588


User avatar
0
sddev created

Hi,

We're trying to extend the OrganizationUnit entity to add some additional items to it.

public class OrganisationUnit : OrganizationUnit
    {
		public virtual bool IsCompany { get; set; }
    }

The updates will allow department information to be added - eg Department Phone Number, Starting Hours etc.

Now when using the Repository against OrganizationUnit, we get all the results but without the additional fields. But when using a Repository against OrganisationUnit we get no results whatsoever:

public class OrganisationUnitManager : IDomainService
{
   private readonly IRepository<OrganisationUnit, long> _organisationUnitRepository;
   private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
      
   public OrganisationUnitManager(IRepository<OrganisationUnit, long> organisationUnitRepository, IRepository<OrganizationUnit, long> organizationUnitRepository, IRepository<UserOrganizationUnit, long> userOrganizationUnitRepository)
   {
      _organisationUnitRepository = organisationUnitRepository;
      _organizationUnitRepository = organizationUnitRepository;
   }
 
 
public async Task<OrganizationUnit> GetOUForUser(long userId)
{
   var orgs = _organisationUnitRepository.GetAll(); // Returns 0 Results - with the extended columns
   var orgz = _organizationUnitRepository.GetAll(); // Returns 8 Results - without the extended columns
   return orgUnit;
}
}

Any thoughts would be great.

Simon


2 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Did you create a record using OrganisationUnit before retrieving it's data?

    Assuming you are using EF Core, table-per-hierarchy (TPH) is used by default. That being said, OrganisationUnit and OrganizatonUnit being stored in the same table but are considered different entities. You can take a look at your organization unit table which will contains a discriminator column.

    If you want to use OrganisationUnit, please ensure all data CRUD are going through OrganisationUnit repository methods.

  • User Avatar
    0
    sddev created

    That's brilliant. Thank you for this. I changed the Discriminator column to be the new name and was able to get all the results, and strangely enough, in both repositorys! So it looks like I might not need to change anything. I'll need to do a bit more testing, but Im happy this is the answer.

    Thank you so much!

    Simon