首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体框架,扩展添加"filters“

实体框架,扩展添加"filters“
EN

Stack Overflow用户
提问于 2010-08-26 17:00:17
回答 1查看 174关注 0票数 0

我有很多像这样的扩展“过滤器”:

代码语言:javascript
复制
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()等,我想根据条件添加这些过滤器。

有点像:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-08-26 19:09:57

只需将它们链接在一起:

代码语言:javascript
复制
var result = _rep.GetCustomers();
if (useByCompanyId)
  _rep = _rep.ByCompanyID(companyId);
if (useByCountry)
  _rep = _rep.ByCountry(county);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3573569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档