开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜