It's a quite common situation when the queries generated by EasyQuery components must have an additional condition(s) not visible to end-users. For example, you may need to limit the result set by user ID, department ID or some time frames. EasyQuery provides you with two possible ways of resolving this task:
1. ''BuildSQLEx()'' method of ''SqlQueryBuilder''
To insert additional conditions into generated SQL statements you can use
BuildSQLEx() function of
SqlQueryBuilder class (instead of
BuildSQL you are using by default) and pass necessary condition(s) in its second parameter. The value of that parameter will be added to a result SQL statement at the end of WHERE clause with AND conjunction to conditions, defined by end-users through visual controls.
The only trick here - you may also need to list all tables which take part in that additional condition using
ExtraTables property of DbQuery class. It's necessary to ensure that all necessary table joins will be included into result SQL.
Korzh.EasyQuery.Db.Table table = model.Tables.FindByName("Customers"); query.ExtraTables.Add(table); SqlQueryBuilder builder = new SqlQueryBuilder(query); builder.BuildSQLEx("", "Customers.CustomerID = 'ALFKI'");
2. ExtraConditions property of Query class
Since version 3.5.0 of EasyQuery ASP.NET you can use more simple and convenient way of inserting extra conditions:
query.ExtraConditions.AddSimpleCondition("Customers.CustomerID", "Equal", "ALFKI");
Now there is no need to deal with
ExtraTables or use the exact SQL expression for your additional condition.
AddSimpleCondition method will take care of everything.