NHibernate QueryOver restrict by string length

nhibernate, nhibernate-criteria, queryover

Solution

Something like this may do the trick

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

Problem

How do I restrict a query by the length of a string property? eg. something like: ``` NHSession.QueryOver<Customer>() .Where(p => p.RegistryCode.Length == 8) ```

Original source