# .NET multi-tenancy: isolate data by SQL Server schema — part 2/4

Canonical source : [.NET multi-tenancy: isolate data by SQL Server schema — part 2/4](<https://sebastien.rigaux.be/en/tech-watch/links/net-multi-tenancy-isolate-data-by-sql-server-schema-part-24>)

Part 2/4 shows how to isolate each tenant’s data in its own SQL Server schema, without a global query filter or a required `TenantId` column. EF Core can use a simple primary key again, while the database structure itself enforces the isolation boundary.

The key change is model caching: `OnModelCreating` runs only once per model. The schema must be included in the cache key through `IModelCacheKeyFactory`, or EF Core may reuse the first tenant’s schema. The article also covers per-schema provisioning and migrations, plus strict validation of schema names interpolated into SQL.

- Selected on : 2026-11-02

- Resource publication : 2026-07-30

- Entry updated : 2026-11-07T20:32:37+0000

- Format : Article

- Source language : EN

- Credit : Barret

- Found via : [C\# Digest](<https://csharpdigest.net/>)

Original resource : [.NET multi-tenancy: isolate data by SQL Server schema — part 2/4](<https://barretblake.dev/posts/development/2026/07/multi-tenant-part-2/>)

Tags : [Multi-tenancy](<https://sebastien.rigaux.be/en/tech-watch/tags/multi-tenancy>) · [.NET](<https://sebastien.rigaux.be/en/tech-watch/tags/dotnet>) · [Entity Framework Core](<https://sebastien.rigaux.be/en/tech-watch/tags/entity-framework-core>) · [SQL Server](<https://sebastien.rigaux.be/en/tech-watch/tags/sql-server>) · [Software Architecture](<https://sebastien.rigaux.be/en/tech-watch/tags/software-architecture>)

Available versions : [Français](<https://sebastien.rigaux.be/veille/liens/net-multi-tenant-separer-les-donnees-par-schema-sql-server-partie-24>) · [English](<https://sebastien.rigaux.be/en/tech-watch/links/net-multi-tenancy-isolate-data-by-sql-server-schema-part-24>)

[Back to tech watch](<https://sebastien.rigaux.be/en/tech-watch>)
