Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do compare strings with nhibernate?

Tags:

c#

nhibernate

I'm trying to do something like:

Session.Query<VoiceMailNumber>()
            .Where(x => (x.From.CompareTo(number) > 0) &&
                  (x.To.CompareTo(number)) > 0)

But that throws System.NotSupportedException.

From and number are both strings.

Any solution?

like image 562
Anders Avatar asked May 22 '26 13:05

Anders


1 Answers

This solves it:

Session.CreateCriteria(typeof(VoiceMailNumber))
                .Add(Expression.Le("From", number))
                .Add(Expression.Ge("To", number))
                .UniqueResult<VoiceMailNumber>();

I'm not super happy with this solution, but since it's not possible to compare strings using query or queryover, it will have to do.

like image 160
Anders Avatar answered May 24 '26 02:05

Anders