我有很多像这样的扩展“过滤器”:
public static IQueryable<Customer> ByCustomerID(this IQueryable<Customer> qry, int customerID)
{
return from c in qry
where c.CustomerID == customerID
select c;
}添加到GetCustomers() (IQueryable),如.ByCompanyID()等,我想根据条件添加这些过滤器。
有点像:
var result = _rep.GetCustomers();
if(useByCompanyID)
// add .ByCompanyID(companyID) to "result"
if(useByCountry)
// add .ByCountry(country) to "result"
// etc etc....
//do something with "result"使用实体框架和linq可以做到这一点吗?
/M
发布于 2010-08-26 19:09:57
只需将它们链接在一起:
var result = _rep.GetCustomers();
if (useByCompanyId)
_rep = _rep.ByCompanyID(companyId);
if (useByCountry)
_rep = _rep.ByCountry(county);https://stackoverflow.com/questions/3573569
复制相似问题