문제

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)
도움이 되었습니까?

해결책

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
        )
    )

다른 팁

Instead of "NHibernateUtil.String" i should use this "NHibernateUtil.Int16" type, because a 'length' parameter should always be a number and not a String.

Something like this:

NHSession.QueryOver<Customer>()
    .Where(
        Restrictions.Eq(
            Projections.SqlFunction("length", NHibernateUtil.Int16, 
                Projections.Property<Customer>(x => x.RegistryCode)),
            8
        )
    )
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top