If you could accept the CAST
instead of CONVERT
(And I am almost sure that you can), then there is more straightforward solution.
Instead of calling "SQL Server related" function, let's call the abstraction, which should be working on most DB Servers (based on supported NHibernate dilacts)
Projections.Cast(NHibernateUtil.String, Projections.Property(searchCol))
So the Restriction
used in a WHERE
clause could look like this:
Restrictions
.Like (
Projections.Cast(NHibernateUtil.String, Projections.Property(searchCol))
, "2009"
, MatchMode.Anywhere
)
And the result generated by NHibernate, using the SQL Server dialect would be:
WHERE cast( this_.theColumn as NVARCHAR(255)) like @p1 ... @p1=N'%2009%'