score:1
You can build expressions dynamically but not as simply as your pseudo code - it requires reflection and expression trees (read this).
A simple way to accomplish what it seems like you'd like to do is to short circuit different parts of the predicate using boolean flags:
bool testMachineName;
bool testIsServer;
r = r.Where( x =>
( !testMachineName || iEnumerableMachineNames.Contains( x.Machine.Name ) ) ||
( !testIsServer || x.Server ) );
Source: stackoverflow.com
Related Articles
- Programmatically building a query with LINQ statement with entity framework
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Entity Framework - Linq query with order by and group by
- Deleting multiple records with Entity Framework using a single LINQ query
- Entity Framework with Oracle using odp.net not taking parameters in linq query
- Entity Framework Core LINQ query with multiple where clauses
- Nested expression building with linq and Entity Framework
- Optimize SQL generated by LINQ Query in Entity Framework 4.1 with one-to-many associations
- How to query many-to-many relationship with 'AND' condition using LINQ and Entity Framework
- Convert String to DateTime in LINQ query with Entity Framework Core
- Entity Framework - LINQ statement with WHERE clause based on NULLABLE parameter
- Dynamic query building with entity framework core - Build a query "by steps"
- Exception raised when using a Linq query with Entity Framework
- Using Linq to query Entity Framework with Where clause and many-to-many relation
- Linq query with many to many relations using entity framework
- entity framework with linq query and stored expression error
- Entity Framework with LINQ query
- Convert Sum(case) SQL statement to LINQ query in Entity Framework
- Searching for multiple strings using single database query with entity framework and LINQ
- How to convert a SQL with multiple left joins to an Entity Framework LINQ statement using Include methods (No Join methods)?
- Entity Framework - convert LINQ method chain with SelectMany to query syntax
- Problem with dynamic query building for Entity Framework Core 3.1.6
- How can I convert Sql query to Linq and its equivalent with Join() method in Entity Framework Core
- Where clause in LINQ Query with Entity Framework
- Execute dynamic query with Linq in Entity Framework
- Need help with a simple Linq query running with Entity Framework 4
- Help with a C# linq query on entity framework objects
- Entity Framework with an Intersect table and correspond Linq query
- Convert SQL query to linq in C# with Entity Framework
- ASP.NET MVC Entity Framework - Linq query with order by
- Linq to CSV DateTime format using C#
- A problem with compare item value
- Why do we need Single() in LINQ?
- Algorithm: two tables are in connection with ID, calculating a new table from them
- Error when converting splitted string
- Linq-to-entities Include method doesn't load related records
- Linq updating different table after join process
- lambda expression in boo
- Linq to entities join not working
- Linq: Adding Extra 'Where' Clause Gives Random Results
- Working With Linq Query in Mapping
- How to get minimum unused number from a column in Oracle and Linq?
- DeleteOnSubmit LINQ exception "Cannot add an entity with a key that is already in use"
- Grouping on DataTable using LINQ
- Cannot implicitly convert type 'int' to 'System.Collections.Generic.List<QuickTest.Stock>'
- Comparing two lists with multiple conditions
- How to extract particular columns values from multiple rows using linq
- Entity Framework LINQ - dynamically select properties
- linq filtering by class type
- multiple Groupby on result of GroupBy Linq