NHibernate通过示例混合喜欢和等于吗? [英] Mixing Likes and Equals with NHibernate Query-By-Example?

查看:89
本文介绍了NHibernate通过示例混合喜欢和等于吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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到处都使用like运算符,我得到它是因为这是我设置它的方式.但是是否可以将某些字段设置为"like"而将某些字段设置为"equals"?我需要Zip5等于Equal,状态要等于E……但是其余的可以像.

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.

还是我只是毁掉了QBE,所以我还是应该使用常规的旧标准?

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

推荐答案

您可以混合

.ExcludeProperty("Zip5")


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

.ExcludeProperty("ADDRESS")


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

这篇关于NHibernate通过示例混合喜欢和等于吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆