queryover and (x like 'a' or y like 'a')

前端 未结 3 791
离开以前
离开以前 2020-12-04 16:16

Hi Is there any elegant way of combining \'like\' and \'or\' when i\'m using queryover API? for \'like\' there is something like:

 query.WhereRestrictionOn(         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 17:19

    You could use the NHibernate Disjunction class to do this in a more elegant (IMHO) fashion:

    var disjunction= new Disjunction();
    
    disjunction.Add(Restrictions.On(e => e.Code).IsLike(codePart));
    disjunction.Add(Restrictions.On(e => e.Description).IsLike(codePart));
    //(and so on)
    

    and then:

    query.Where(disjunction)
    

    Each "OR" is a separate instruction, which helps if you want to add the predicates conditionally.

提交回复
热议问题