我正在使用共享数据库和共享架构方法构建多租户应用程序。所以根据方法,我在每个表中都有“Tenant_Id”列。那么有没有办法在每个查询中自动附加where子句......
答案 0 :(得分:5)
您可以使用DbContext
周围的包装器来实现此目的,并使用where子句覆盖每个实体集合。
public class WrapperContext : YourDBContext
{
public override DbSet<YourEntitity> YourEntities
{
get
{
return base.YourEntities.Where(t => t.Tenant_Id == someId);
}
set
{
base.YourEntities = value;
}
}
}