Base solution for your next web application
Open Closed

Extending OrganizationUnit entity with IMustHaveTenant #7154


User avatar
0
rucksackdigital created

Hello,

I've built out a new entity that extends the OrganizationUnit with a new field, and some additional new table as references. Everything is working smoothly, however I'd like to enforce tenantId requirements on my entity with IMustHaveTenant. The issue I'm running is when running add-migration, VS insists on trying to add tenantId to the abporganizationunits table, even though it's already there. I've tried adding [NotMapped] annotation to the tenantID in my class but that doesnt' seem to work.

Is there a way to do this that I'm missing, or should I just add checks for tenantId.HasValue in my domain service (which is what I'm doing now), before progressing with business logic?


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

    Hi,

    OrganizationUnit already has IMayHaveTenant interface which has int? TenantId. When you added IMustHaveTenant, EF Core most likely treating these two properties as different columns.

    I would suggest to revisit the need to enforce tenant id on the extended entity or it might be easier to create another entity with IMustHaveTenant and link it to OrganizationUnit

  • User Avatar
    0
    rucksackdigital created

    @ryancyq not sure why I never thought to do a simple association. That works quite nicely, thanks for the feedback. I ended up creating an Xyz entity with IMustHaveTenant enforced, linked to an XyzOU derived class and doing tenantId validation one save