我有以下条件查询:
Criteria criteria = session.createCriteria(Parts.class);
Iterator<String> iterator = searchList.iterator();
Disjunction or = Restrictions.disjunction();
while (iterator.hasNext()){
or.add(Restrictions.like("partName", "%"+iterator.next()+"%"));
}
criteria.add(or);
criteria.add(Restrictions.in("partType", partType));
criteria.addOrder(Order.asc("partDesc"));
产生以下where子句:
from PartsDb..Parts this_ where (this_.PartName like ? or this_.PartName like ? or this_.PartName like ?) and this_.PartType in (?, ?) order by this_.PartDesc asc
整个&#39; OR&#39;子句在括号中没有给出正确的结果。我希望查询是这样的(没有围绕OR子句的大括号):
from PartsDb..Parts this_ where this_.PartName like ? or this_.PartName like ? and this_.PartType in (?, ?) order by this_.PartDesc asc
所以我想写这个:
Select * from dbo.Parts
where
PartName like '%ABC%'
or PartName like '%XYZ%'
or PartName like '%PQR%'
....
...
and PartType in ('a','b')
...
&#39; searchList&#39;中的对象数量将根据用户输入的内容而有所不同。有关如何获得变量数量的任何帮助&#39; OR&#39;大括号中的条款将受到高度赞赏!!
由于