我有一个过滤器
this.Filter<BaseModel>(q => q.Where(x => x.CompanyId == companyId);
有没有办法检查“x”正在实现我的自定义界面“IGlobalDatabaseObject”?
this.Filter<BaseModel>(q => q.Where(x => x.CompanyId == companyId || x is IGlobalDatabaseObject ); ?
因此,db查询将返回“x.CompanyId == companyId”的数据,或者该数据是否实现全局接口
我正在使用Ef plus库(github.com/zzzprojects/EntityFramework-Plus)
答案 0 :(得分:2)
我认为您正在寻找 EF+ Query Filter Enable/Disable功能。在你的情况下,像这样:
// The key identifying your filter
var key = new object();
// Create filter for classes that inherit BaseModel
this.Filter<BaseModel>(key, q => q.Where(x => x.CompanyId == companyId));
// Disable the filter for classes that implement IGlobalDatabaseObject
this.Filter<IGlobalDatabaseObject>(key).Disable();