I'm currently working on a column-based multitenant app. I added tenantId on each entity with a base class, and used query filters which fits perfectly my needs. I also overrided savechanges method to populate tenantid property on added entities using the changetracker.
But now i'm stuck with update and delete. As far as i know, ef generates a where clause with only primary key, which is very unsafe for me, because i work on an api environment with a lot of attach/detach stuff, and wrote a lot of entity.state = modified instead of querying first, in order to improve performance.
My question is : how to add a predicate to an ef core update/delete statement ?
I know that i can : 1. Query first (and i'm pretty sure you'll recommand me this) 2. Make tenantid as a part of a compositekey, but this would really be painfull to refactor all my code as the add/find/etc. Methods need full primary keys.
I would be really gratefull to anyone who knows how to trigger this !