将“喜欢”和“等于”与 NHibernate 示例查询混合在一起?

发布于 2024-12-11 05:35:27 字数 1304 浏览 2 评论 0原文

我有一个相当大的 SOA 解决方案和一个新添加的服务,使用 NHibernate 的 Query By Examples 查询大约 980 万条记录。到目前为止,性能一直很糟糕,数据库上的配置文件将查询显示为:

exec sp_executesql N'SELECT this_.Id as Id3_0_, this_.ESIID as ESIID3_0_, this_.ADDRESS as ADDRESS3_0_, this_.ADDRESS_OVERFLOW as ADDRESS4_3_0_, this_.CITY as CITY3_0_, this_.STATE as STATE3_0_, this_.ZIP5 as ZIP7_3_0_, this_.ZIP4 as ZIP8_3_0_, this_.DUNS as DUNS3_0_, this_.PREMISE_TYPE as PREMISE10_3_0_, this_.STATUS as STATUS3_0_, this_.METER_READ_CYCLE as METER12_3_0_, this_.STATIONCODE as STATION13_3_0_ FROM vw_TDSP_ESIID this_ WHERE (lower(this_.ADDRESS) like lower(@p0) and lower(this_.CITY) like lower(@p1) and lower(this_.STATE) like lower(@p2) and lower(this_.ZIP5) like lower(@p3) and lower(this_.ZIP4) like lower(@p4))',N'@p0 nvarchar(10),@p1 nvarchar(2),@p2 nvarchar(4),@p3 nvarchar(7),@p4 nvarchar(2)',@p0=N'%110 Main%',@p1=N'%%',@p2=N'%TX%',@p3=N'%77002%',@p4=N'%%'

所以,基本上是因为我的代码看起来像:

var queryEx = Example.Create(esiIdEntityProto)
            .EnableLike(MatchMode.Anywhere)
            .ExcludeNulls()
            .ExcludeZeroes()
            .IgnoreCase();

NHib 到处都使用 like 运算符,我得到它是因为这就是我设置它的方式。但是是否可以将某些字段设置为相似,将某些字段设置为相等?我需要 Zip5 是 EQUAL 并声明是 EQUAL...但其余的可以是 LIKE。

或者我只是毁了 QBE,所以我不妨使用常规的旧标准?

I have a rather large SOA solution and a newly added service queries approx 9.8 million records using NHibernate's Query By Example. Thus far the performance has been terrible, and a profile on the database shows the query as:

exec sp_executesql N'SELECT this_.Id as Id3_0_, this_.ESIID as ESIID3_0_, this_.ADDRESS as ADDRESS3_0_, this_.ADDRESS_OVERFLOW as ADDRESS4_3_0_, this_.CITY as CITY3_0_, this_.STATE as STATE3_0_, this_.ZIP5 as ZIP7_3_0_, this_.ZIP4 as ZIP8_3_0_, this_.DUNS as DUNS3_0_, this_.PREMISE_TYPE as PREMISE10_3_0_, this_.STATUS as STATUS3_0_, this_.METER_READ_CYCLE as METER12_3_0_, this_.STATIONCODE as STATION13_3_0_ FROM vw_TDSP_ESIID this_ WHERE (lower(this_.ADDRESS) like lower(@p0) and lower(this_.CITY) like lower(@p1) and lower(this_.STATE) like lower(@p2) and lower(this_.ZIP5) like lower(@p3) and lower(this_.ZIP4) like lower(@p4))',N'@p0 nvarchar(10),@p1 nvarchar(2),@p2 nvarchar(4),@p3 nvarchar(7),@p4 nvarchar(2)',@p0=N'%110 Main%',@p1=N'%%',@p2=N'%TX%',@p3=N'%77002%',@p4=N'%%'

So, basically because my code looks like:

var queryEx = Example.Create(esiIdEntityProto)
            .EnableLike(MatchMode.Anywhere)
            .ExcludeNulls()
            .ExcludeZeroes()
            .IgnoreCase();

NHib is using the like operator everywhere, which I get because that's how I set it up. But is it possible to set up some fields to be like and some to be equals? I need Zip5 to be EQUAL and state to be EQUAL...but the rest can be LIKE.

Or did I just ruin QBE so I might as well use regular old criteria?

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

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

发布评论

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

评论(1

沉溺在你眼里的海 2024-12-18 05:35:27

你可以混合

.ExcludeProperty("Zip5")


.Add(example).Add(Restrictions.Eq("Zip5", esiIdEntityProto.Zip5))

.ExcludeProperty("ADDRESS")


.Add(example).Add(Restrictions.Like("ADDRESS", esiIdEntityProto.Address))

you can mix

.ExcludeProperty("Zip5")


.Add(example).Add(Restrictions.Eq("Zip5", esiIdEntityProto.Zip5))

or

.ExcludeProperty("ADDRESS")


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