EntityFramework-加上检查数据是否实现接口
EntityFramework-Plus check if data implements an interface
我有一个过滤器
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 ); ?
因此,数据库查询将 return 数据 "x.CompanyId== companyId" 或者如果该数据实现全局接口
我正在使用 Ef plus 库 (github.com/zzzprojects/EntityFramework-Plus )
我想你正在寻找
EF+ 查询过滤器 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();
我有一个过滤器
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 ); ?
因此,数据库查询将 return 数据 "x.CompanyId== companyId" 或者如果该数据实现全局接口
我正在使用 Ef plus 库 (github.com/zzzprojects/EntityFramework-Plus )
我想你正在寻找 EF+ 查询过滤器 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();