NHibernate 3 - How to perform a LIKE on an id/numeric/int
-
23-01-2021 - |
Question
Whilst SQL Server is perfectly comfortable doing:
where Id like '45%'
(id being an int), NH will complain as it will still try to send the compare value into sql as a SqlParameter of type int when doing:
q.WhereRestrictionOn(cl => cl.CompanyId).IsLike(companyIdFilter)
So how to get round it with the new QueryOver API?
Solution
After some digging around and and trial and error, this does the trick:
q.Where(Expression.Like(
Projections.Cast(
NHibernateUtil.String,
Projections.Property<ChangeLog>(cl => cl.CompanyId)),
companyIdFilter.Value.ToString(),
MatchMode.Start
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow