0

我尝试将SelectQueryBuilder用于以下查询,但它并没有达到应有的效果。

我想要一个这样的查询字符串

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

但我得到的是

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

我的代码是:

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();

如何在语句本身中添加 LogicOperator.Or?

谢谢。

4

1 回答 1

0

尝试使用AddWhere方法重载。它有level参数来决定嵌套条件的级别

我从来不需要尝试这些关卡,所以让我知道你遇到了什么,我会尽力提供更多帮助:)

快乐编码

于 2015-06-15T12:09:29.287 回答