[question] Dynamic OR clause in where statement
See original GitHub issueHow to create the dynamic query with OR clause. For example I have 2 tables Orders, OrderLines and I need to create dynamic OR filter. Small example with pseudo code.
var query = (
from o in db.Orders
from ol in db.OrderLines.Where(ol => o.OrderId == ol.OrderId)
select new QueryData { Order = o, OrderLine = ol } );
if(status > 0)
query = query.Where(arg => arg.Order.Status == status );
var orFilters = new List<Expression<Func<QueryData, bool>>>();
if(filters1.Count > 0)
orFilters.Add(CreateFilter1(filters1))
if(filters2.Count > 0)
orFilters.Add(CreateFilter2(filters2))
query = query.Or(orFilters);
class QueryData
{
Order Order { get; aet; }
OrderLines OrderLines { get; aet; }
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Building dynamic where condition in SQL statement
An expression of non-boolean type specified in a context where a condition is expected, near 'set'.
Read more >Implementing Dynamic WHERE-Clause in Static SQL
You can see in example 2.2 - WHERE -clause is built dynamically using the ISNULL function. It evaluates the expression and checks whether...
Read more >Dynamic SQL in SQL Server
Dynamic SQL is the SQL statement that is constructed and executed at runtime based on input parameters passed. Let us go through some...
Read more >Providing variable input to dynamically executed SQL ...
In a dynamic SQL statement, parameter markers are used instead of host variables. A parameter marker is indicated by a question mark (?)...
Read more >Sql based on dynamic where condition
1 Answer 1 · There are multiple conditions based on parameter. In this example 3 different conditions i.e. equal to or greater than...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In your example, it would be used like this:
Closing as answered.