Search code examples
c#nhibernatefluent-nhibernate

NHibernate queryover how to query a field which starts with any value in a list


How to write a proper nhibernate queryover query to select records from a table which has got a column value which starts with any of the value in my inmemory list?

I am trying something like below

select * from table where title like 'AA%' or 'BB%' or 'CC%'

Thanks


Solution

  • I have not tested this, but I think it goes like this.

    var disjunction = new Disjunction();
    
    disjunction.Add(Restrictions.On<YourType>(x => x.Title).IsLike('AA%');
    disjunction.Add(Restrictions.On<YourType>(x => x.Title).IsLike('BB%');
    disjunction.Add(Restrictions.On<YourType>(x => x.Title).IsLike('CC%');
    
    _session.QueryOver<YourType>().Where(disjunction);