using System.Collections.Generic;
public static void Main()
List<Group> groups = new List<Group>
Conditions = new List<Condition>
new Condition {Field = "Country", Operator = "=", Value="United States", clauseOperator = ""},
new Condition {Field = "Country", Operator = "=", Value="Russia", clauseOperator = "OR"}
Conditions = new List<Condition>
new Condition {Field = "Data Source", Operator = "=", Value="Network", clauseOperator = ""},
new Condition {Field = "Data Source", Operator = ">=", Value="NSA", clauseOperator = "OR"}
}, clauseOperator = "AND"
var query = new Query("Countries");
foreach (Group group in groups)
if ( group.clauseOperator == "AND" )
foreach (Condition c in group.Conditions)
if ( c.clauseOperator == "OR" )
q.OrWhere(c.Field, c.Operator, c.Value);
q.Where(c.Field, c.Operator, c.Value);
foreach (Condition c in group.Conditions)
if ( c.clauseOperator == "OR" )
q.OrWhere(c.Field, c.Operator, c.Value);
q.Where(c.Field, c.Operator, c.Value);
query.Where("Id", "=", 10);
Console.WriteLine(new SqlServerCompiler().Compile(query).Sql);
public List<Condition> Conditions { get; set; }
public string clauseOperator { get; set; }
public string Field { get; set; }
public string Operator { get; set; }
public object Value { get; set; }
public string clauseOperator { get; set; }