delicye7
delicye7

Reputation: 1

Entity Framework and PostgreSQL Multi-tenancy using multiple schemas

I'm using Entity Framework Core with PostgreSQL, and I plan to implement multi-tenancy with a single database and multiple schemas. I'm interested in learning more about this and have a few questions

I'm developing an application where I've conceived the idea of using a single database with multiple schemas. In the 'public' schema, I intend to have only some tables related to common aspects, for instance, a 'Stores' table that should contain store names, store IDs, and the name of the schema it belongs to. Meanwhile, other schemas would represent each individual store, and within those schemas, I would need, for example, an 'Items' table displaying items specific to each schema. I'm using PostgreSQL as the database with Entity Framework Core. I'm curious if it's possible to achieve this with Entity Framework Core, and what would be the best approach to implement it?

Upvotes: -1

Views: 223

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89361

Possible and documented. Each DbContext instance would be configured on creation to point to a specific schema for a subset of entities.

protected override void OnModelCreating(ModelBuilder modelBuilder) =>
    modelBuilder.Entity<CustomerData>().ToTable(nameof(CustomerData), tenant);

EF Core Multi-tenancy Multiple Schemas

Upvotes: 0

Related Questions