1

我有一个相当大的 SOA 解决方案和一个新添加的服务,使用 NHibernate 的 Query By Example 查询大约 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 是平等的并且状态是平等的......但其余的可以是 LIKE。

还是我只是毁了 QBE,所以我还不如使用常规的旧标准?

4

1 回答 1

2

你可以混合

.ExcludeProperty("Zip5")


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

或者

.ExcludeProperty("ADDRESS")


.Add(example).Add(Restrictions.Like("ADDRESS", esiIdEntityProto.Address))
于 2011-10-21T07:09:53.543 回答