Search code examples
sql-servernhibernatenhibernate-criteria

Is it possible to make an Nhibernate query generate columnName<>'value' rather than not(columnName='value')?)


Is it possible to make an Nhibernate query generate Sql that has columnName<>'value' rather than not(columnName='value')?

I am told that using not() can have Sql performance issues over <>.

Typically I am writing my queries like this...

criteria.Add(Restrictions.WhereNot<Region>(r => r.Id == region.Id));

which results in

WHERE  not (this_.RegionID = 2048)

UPDATE

This question suggests that there is no longer any performance issues with coding one way or the other

In SQL Server is there any difference between not(columnName='value') and columnName<>'value'?


Solution

  • I think that option is not available in criteria api.But you can use Expression.Sql() as follow

    criteria.Add(Expression.Sql("columnName <>'value'"));