是否可以让 Nhibernate 查询生成 columnName<>'value'而不是 not(columnName='value')?)

发布于 2024-12-26 06:17:11 字数 621 浏览 4 评论 0 原文

是否可以使 Nhibernate 查询生成具有 columnName<>'value' 而不是 not(columnName='value') 的 Sql?

我被告知使用 not() 可能会导致 Sql 性能问题超过 <>。

通常我会像这样编写查询...

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

这会导致

WHERE  not (this_.RegionID = 2048)

更新

此问题表明以一种或另一种方式编码不再存在任何性能问题

在 SQL Server 中,之间有什么区别not(columnName='value') 和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'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2025-01-02 06:17:11

我认为该选项在 criteria api 中不可用。但是您可以使用 Expression.Sql() 如下

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

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

criteria.Add(Expression.Sql("columnName <>'value'")); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文