NHibernate Query which mimics SQL replace function

I have a phone number field that can have many different characters like "-" "." ("") "etc. I want to find a phone number, but I want to exclude certain characters. I'm not sure how to mimic this functionality using NHibernate Criteria or HQL.

+1


a source to share


1 answer


As a result, I used a constrained SQL Criteria query. It was something like this

Session.CreateCriteria<EntityName>()
.Add(Restrictions.Sql(
"Replace('ColumnToSearch','PatternToFind', 'ReplaceWithValue')"))

      



Sql constraint allows you to run the same sql expression as you do.

+3


a source







All Articles