Entity Framework Core Interview Question #197
How should multi-tenant EF Core systems protect tenant data?
Testing, Production Practices & Senior Real-World Scenarios Senior Advanced
Quick Interview Answer
Tenant isolation must be enforced consistently for both reads and writes. Global query filters can help with reads, but authorization, tenant-key assignment, unique constraints, administrative bypasses, raw SQL, background jobs, and migrations also require tenant-aware design. Treat tenant boundaries as a security requirement and test attempts to access another tenant's data.
Detailed Explanation
Tenant isolation must be enforced consistently for both reads and writes. Global query filters can help with reads, but authorization, tenant-key assignment, unique constraints, administrative bypasses, raw SQL, background jobs, and migrations also require tenant-aware design. Treat tenant boundaries as a security requirement and test attempts to access another tenant's data.
Code Example
modelBuilder.Entity<Order>()
.HasQueryFilter(o => o.TenantId == _tenantId);