c# - Nhibernate - Using a column value in QueryOver.IsLike -


i need execute query looks in sql:

select * codes value1 '%' + value2 + '%' 

is there way using fluentnhibernate , queryover? looking this

session.query<code>().whererestrictionon(c => c.value1).islike(c => c.value2); 

but unfortunately islike requires object or string value argument.

as suggested use sql criterion. i'd put in extension method though it's bit more reusable if it's find using every often. this...

    public static iqueryover<troot, tsubtype> wherelike<troot, tsubtype>(this iqueryover<troot, tsubtype> query, expression<func<tsubtype, object>> thislike, expression<func<tsubtype, object>> likethis)     {         var propname1 = expressionprocessor.findmemberexpression(thislike.body);         var propname2 = expressionprocessor.findmemberexpression(likethis.body);         query.where(nhibernate.criterion.expression.sql(string.format(" {0} '%' + {1} + '%' ", propname1, propname2)));         return query;     } 

use so

            var query = session.queryover<code>()                 .wherelike(thislike => thislike.value1, likethis => likethis.value2); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -