0
我有許多擴展 「過濾器」,如這一個:實體框架,延伸加入 「過濾器」
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
_rep可是沒有任何過濾器,只是那些方法,如GetCustomers的() – 2010-08-26 11:29:21
_rep被聲明爲IQueryable的?然後它有任何方法decalred作爲擴展方法(這個IQueryable )。如果_rep不是IQueryable 那麼它需要! –
amaca
2010-08-26 11:35:52
是的,那是有效的。 IQueryable result = _rep.GetCustomers();訣竅。謝謝 –
2010-08-26 11:50:12