有没有办法防止NHibernate LINQ提供程序的布尔性能问题

时间:2011-05-26 19:47:52

标签: c# nhibernate linq-to-nhibernate

我们使用的是NHibernate 2.1,我将系统升级到3.0以测试新的LINQ提供程序。 我比较了linq提供程序,createquery和queryover。

Createquery和queryover几乎完全相同,性能相同。 然而,LINQ提供商做了一些非常时髦的东西!

        var items = (from m in NHibernateSession.Current.Query<Listing>()
                     where m.Active == true
                     select m).Take(10).ToList();

        var items2 = NHibernateSession.Current.CreateQuery("from Listing where Active = :val").SetBoolean("val", true).SetMaxResults(10).List();


        var items3 = NHibernateSession.Current.QueryOver<Listing>()
            .Where(m => m.Active == true)
            .Take(10).List();

来自createquery&amp;的Sql queryover:

select TOP ( 10 /* @p0 */ ) listing0_.PackageID      as PackageID13_,
               listing0_.MatchComplete  as MatchCom2_13_,
               listing0_.ExpirationDate as Expirati3_13_,
               listing0_.Active         as Active13_,
               listing0_.Archived       as Archived13_,
               listing0_.Deleted        as Deleted13_,
               listing0_.UserID         as UserID13_
from   Marketplace.Listings listing0_
where  listing0_.Active = 1 /* @p1 */

来自LINQ的查询:

select TOP ( 10 /* @p0 */ ) listing0_.PackageID      as PackageID13_,
               listing0_.MatchComplete  as MatchCom2_13_,
               listing0_.ExpirationDate as Expirati3_13_,
               listing0_.Active         as Active13_,
               listing0_.Archived       as Archived13_,
               listing0_.Deleted        as Deleted13_,
               listing0_.UserID         as UserID13_
from   Marketplace.Listings listing0_
where  case 
     when listing0_.Active = 1 then 'true'
     else 'false'
   end = case 
           when 'True' /* @p1 */ = 'true' then 'true'
           else 'false'
         end

NH Profiler对LINQ的持续时间为37/91,而2/2

这应该发生吗?或者我错过了一个配置设置,告诉LINQ将布尔比较转换为位?

由于

1 个答案:

答案 0 :(得分:1)

发现解决方案是3.2。这被报告为一个错误,并在下一个版本中修复。