EntityFramework-Plus检查数据是否实现了接口

时间:2017-07-06 11:01:04

标签: c# entity-framework entity-framework-plus

我有一个过滤器

 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)

1 个答案:

答案 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();