How to use CodeEngine.Framework.QueryBuilder.SelectQueryBuilder for the following query in asp.net c#?

1.3k views Asked by At

I tried to use the SelectQueryBuilder for the following query,but it is not coming exactly as it should be.

I want a Query String Like this

SELECT * FROM CustomerData WHERE (CustomerType = 'SPC3' OR CustomerType = 'SPC2' OR CustomerType = 'SPC5') AND Country='UK'

but what I am getting is

SELECT * FROM CustomerData WHERE ((CustomerType = 'SPC3' OR CustomerType = 'SPC3') AND (CustomerType = 'SPC2' OR CustomerType = 'SPC2') AND (CustomerType = 'SPC5' OR CustomerType = 'SPC5')) AND country='UK'

My code is:

var query = new SelectQueryBuilder();
query.SelectFromTable("CustomerData");
query.SelectAllColumns();
query.AddWhere("CustomerType", Comparison.Equals,"UK");

foreach (var selectedCustomerType in selectedCustomerList)
{
WhereClause whereClause = query.AddWhere("CustomerType", Comparison.Equals, selectedCustomerType);
whereClause.AddClause(LogicOperator.Or, Comparison.Equals, selectedCustomerType);
}

String queryStatement = query.BuildQuery();

How can I add LogicOperator.Or in the statement itself ?

Thanks.

1

There are 1 answers

0
Katia On

Try using the AddWhere method overload. it has level parameter to decide what level of where nesting the condition goes to

I never had the need to try the levels so let me know what turns up with you and I'll try to help more :)

Happy coding