我有一个类有
的方法public IEnumerable<string> ProductsStaleResults()
{
using(var context = DataContext.FromID(Id))
{
return
(from change in context.ProductChangeTrackings
join product in context.Products
on change.SKU equals product.SKU
where product.Status == ProductStatus.Active
from rule in context.ProductDataQualityRules
where rule.Status == "Active"
&&
(
from result in context.ProductDataQualityResults
where result.ProductDataQualityRuleID == rule.ProductDataQualityRuleID
&& result.SKU == change.SKU
select result.ProductRowVersion
).Any(prv => prv == change.RowVersion) == false
select change.SKU).Distinct();
}
}
问题是我需要运行一个集成测试,只过滤context.ProductDataQualityRules
中的某些实体。理想情况下,不更改此类本身(可能会扩展它)。
所以我想以某种方式注入一个Func<ProductDataQualityRule, bool> filter
以便
from rule in context.ProductDataQualityRules
where rule.Status == "Active"
表现得像
from rule in context.ProductDataQualityRules
where rule.Status == "Active" && filter(rule)
这是可能的,如果是的话,怎么样?