6

我正在使用共享数据库和共享模式方法构建多租户应用程序。因此,按照方法,我的每个表中都有“Tenant_Id”列。那么有没有办法在每个查询中自动附加一个where子句......

4

1 回答 1

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;
    }
  }      
}
于 2012-05-20T12:26:12.937 回答