Conditional LINQ where statement?

后端 未结 1 1775
遇见更好的自我
遇见更好的自我 2021-01-14 08:14

I have a linq statement that I want to add an additional where clause to if a drop down index is not 0.

people.Where(n.surname == \"surname\" || n.forename =         


        
相关标签:
1条回答
  • 2021-01-14 08:44

    Fortunately, this is easy because queries compose:

    var query = people.Where(n.surname == "surname" || n.forename == "forename");
    if (dropdown.SelectedIndex > 0)
    {
        query = query.Where(n => n.id.ToString() == dropdown.SelectedValue);
    }
    
    0 讨论(0)
提交回复
热议问题