How do I combine LINQ expressions into one?

前端 未结 3 1224
天涯浪人
天涯浪人 2020-12-10 01:39

I\'ve got a form with multiple fields on it (company name, postcode, etc.) which allows a user to search for companies in a database. If the user enters values in more than

3条回答
  •  猫巷女王i
    2020-12-10 02:27

    EDIT: Jason's answer is now fuller than mine was in terms of the expression tree stuff, so I've removed that bit. However, I wanted to leave this:

    I assume you're using these for a Where clause... why not just call Where with each expression in turn? That should have the same effect:

    var query = ...;
    foreach (var condition in conditions)
    {
        query = query.Where(condition);
    }
    

提交回复
热议问题