Hi, If an entity implements IMustHaveOrganizationUnit accepts zero as valid parameter. In the same entity, that implements also IMustHaveTenantId, an exceptions is throw is TenantId equals to zero. So, if the input dto is missing of OrganizationUnitId, the record is registered anyway. It's by design or I'm missing something?
Thank you.
1 Answer(s)
-
0
Hi,
ABP has not a feature that checks if foreign keys are properly filled. You should validate it in your code. 0 is not only the problem. User may pass 89734243 as organization unit id and it may not be in the database. Will you save it in this case? So, as a best practice, get OU from database with given id and check if it does exists.
This is also true for any foreign key property. ABP can not validate all.
BTW, you can easily validate OrganizationUnitId for input DTO. Just put a [Range(1, int.MaxValue)] attribute to the property in DTO. Thus, user can not pass 0.
Multitenancy is a special case and TenantId is not sent by clients. It should be correctly set by you in the code. We could do same for all entities with integer PK, but 0 is not the only problem as I described before.