NHibernate QueryOver limits string length

How to limit the request to the length of the string property? eg. sort of:

NHSession.QueryOver<Customer>() .Where(p => p.RegistryCode.Length == 8) 
+4
source share
2 answers

Something like this might do the trick.

 NHSession.QueryOver<Customer>() .Where( Restrictions.Eq( Projections.SqlFunction("length", NHibernateUtil.String, Projections.Property<Customer>(x => x.RegistryCode)), 8 ) ) 
+4
source

Instead of "NHibernateUtil.String" I should use this type of "NHibernateUtil.Int16" because the parameter "length" should always be a number, not a string.

Something like that:

 NHSession.QueryOver<Customer>() .Where( Restrictions.Eq( Projections.SqlFunction("length", NHibernateUtil.Int16, Projections.Property<Customer>(x => x.RegistryCode)), 8 ) ) 
+1
source

Source: https://habr.com/ru/post/1499376/


All Articles