c# - NHibernate selecting from a many to many collection and use 'or' between different tables -
i nhibernate generate following sql i'm stuggling code below
select * [tcrm_client] ( [id] in ( select b.clientid tcrm_contact a,r_client_contact b a.id = b.contactid , ( a.mobile 'keyword%' or a.tel 'keyword%' ) ) or name '%keyword%' ) private void addcriterion<t>(iqueryover<t, t> query) t : client { if (!string.isnullorempty(keyword)) { var r1 = (restrictions.on<client>(x => x.name) .islike("%" + keyword + "%", matchmode.start)); var profilequery = query.left.joinqueryover<clientcontact> (o => o.clientcontactlist) .left.joinqueryover<contact>(x => x.contact).where(o => o.id != guid.empty); var r2 = restrictions.on<contact>(x => x.tel) .islike("%" + keyword + "%", matchmode.start) || restrictions.on<contact>(x => x.mobile) .islike("%" + keyword + "%",matchmode.start); //a failed attempt //query.add(r1) //profilequery.add(r2); //another failed attempt //query.rootcriteria.add(restrictions.or(r1,r2)); } }
these code cannot works because of not use keyword 'or' between different tables currently.
select b.clientid tcrm_contact a,r_client_contact b a.id = b.contactid , a.mobile 'keyword%' union select b.clientid tcrm_contact a,r_client_contact b a.id = b.contactid , a.tel 'keyword%'
you can try use instead of .
Comments
Post a Comment