2011-05-26 41 views
4

我們使用的是NHibernate 2.1,我將系統升級到3.0以測試新的LINQ提供程序。 我比較了linq提供程序,createquery和queryover。有沒有一種方法可以防止NHibernate LINQ提供程序的布爾性能問題

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 & queryover SQL:

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探查對LINQ持續時間九十一分之三十七相比2/2

這是否應該發生?或者我錯過了一個配置設置,告訴LINQ將布爾比較轉換爲位?

謝謝

+0

這很有趣。你是否有可能導致這種情況的自定義'IUserType'實現? – kprobst 2011-05-26 20:29:19

+1

如果嘗試(m => m.Active)作爲謂詞而不是(m => m.Active == true),會發生什麼? – mbeckish 2011-05-26 20:33:57

+0

@mbeckish沒有變化。我也試過標準查詢語法,它和查詢完全一樣。 – BradLaney 2011-05-26 20:41:52

回答

1

發現解決方案是在3.2。這被報告爲一個錯誤,併爲下一個版本修復。

相關問題