EntityFramework-Plus check if data implements an interface


I have a filter

 this.Filter<BaseModel>(q => q.Where(x => x.CompanyId == companyId);

Is there a way to check whatever "x" is implementing my custom interface "IGlobalDatabaseObject" ?

 this.Filter<BaseModel>(q => q.Where(x => x.CompanyId == companyId || x is IGlobalDatabaseObject ); ?

So, the db queries will return the data where "x.CompanyId== companyId" or if that data implements Global Interface

I am using Ef plus library (github.com/zzzprojects/EntityFramework-Plus )

Accepted Answer

I think you are seeking for EF+ Query Filter Enable/Disable feature. In your case, something like this:

// 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

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why