NHibernate 3 - How to perform a LIKE on an id/numeric/int
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 =&g开发者_如何学Got; cl.CompanyId).IsLike(companyIdFilter)
So how to get round it with the new QueryOver API?
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
));
精彩评论