dotnet / dotnet/EntityFramework.Docs

Document multitenancy technique via tenant column (with RLS)

Open
#4,847 2 comments 0 reactions 0 assignees View on GitHub
area-multi-tenant
Dominant language
Mermaid
Stars
1.7k
Forks
2k
Avg merge
7d 23h
Merged PRs (30d)
16

Description

### Type of issue

Other (describe below)

### Description

I would not call it an issue at all, but I'd suggest if possible, extending the documentation with an explicit statement, that in most cases `tenant` column should exist in every table containing multitenant data (case of single database).

There are multiple reasons for it:

- Enabled Row Level Security on DB side. (unfortunately, you do not mention [this db feature](https://learn.microsoft.com/en-us/sql/relational-databases/security/row-level-security?view=sql-server-ver16#UseCases))
- Tenant is a natural shard key for the table + it should be the first component of almost any index.
- Can define a simple global filter that does not require navigation properties to the entities which hold reference to the tenant. (that is no joins)
- Easy to introduce an interceptor to check that modified entities belong to the active tenant.

Why do I ask for this? Well, I believe recommendation from EF team will have more weight than my words.

### Page URL

https://learn.microsoft.com/en-us/ef/core/miscellaneous/multitenancy

### Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/miscellaneous/multitenancy.md

### Document Version Independent Id

bb29a2b6-c401-287f-2da9-1aeb3c633b41

### Article author

@JeremyLikness

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.