You can certainly do it within a Where clause (extension method). If you need to build a complex query dynamically, though, you can use a PredicateBuilder.

 var query = collection.Where( c => c.A == 1 || c.B == 2 );

Or using a PredicateBuilder

 var predicate = PredicateBuilder.False<Foo>();
 predicate = predicate.Or( f => f.A == 1 );
 if (allowB)
 {
    predicate = predicate.Or( f => f.B == 1 );
 }

 var query = collection.Where( predicate );

 

参考:

https://stackoverflow.com/questions/2101540/or-equivalent-in-linq-where-lambda-expression

相关文章:

  • 2022-12-23
  • 2021-06-01
  • 2022-12-23
  • 2021-09-03
  • 2022-02-21
  • 2021-08-03
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2021-09-15
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
相关资源
相似解决方案