Multi-tenant application and entity infrastructure

I am creating a multi-user application with shared database access and shared schemas. So, according to the approach, I have a “Tenant_Id” column in each of my tables. So, is there a way to automatically assign a where clause in every request ...

+6
source share
1 answer

You can achieve this by using a wrapper around your DbContext and overriding each entity collection with a where clause.

 public class WrapperContext : YourDBContext { public override DbSet<YourEntitity> YourEntities { get { return base.YourEntities.Where(t => t.Tenant_Id == someId); } set { base.YourEntities = value; } } } 
+5
source

Source: https://habr.com/ru/post/916194/


All Articles