Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用共享数据库和共享模式方法构建多租户应用程序。因此,按照方法,我的每个表中都有“Tenant_Id”列。那么有没有办法在每个查询中自动附加一个where子句......
您可以使用包装器来实现此目的DbContext,并使用 where 子句覆盖每个实体集合。
DbContext
public class WrapperContext : YourDBContext { public override DbSet<YourEntitity> YourEntities { get { return base.YourEntities.Where(t => t.Tenant_Id == someId); } set { base.YourEntities = value; } } }