How do I implement a dynamic 'where' clause in LINQ?

后端 未结 7 2108
有刺的猬
有刺的猬 2020-12-29 09:57

I want to have a dynamic where condition.

In the following example:

var opportunites =  from opp in oppDC.Opportunities
                        


        
7条回答
  •  春和景丽
    2020-12-29 10:47

    Because queries are composable, you can just build the query in steps.

    var query = table.Selec(row => row.Foo);
    
    if (someCondition)
    {
        query = query.Where(item => anotherCondition(item));
    }
    

提交回复
热议问题