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?
you can mix
or