NHibernate 2.0 を使用しており、上位 2 つのレコードを返すよう要求する要求を送信すると、SQL に多数の ORDER BY 句が含まれています。Max の結果を取り出すと、クエリは問題ないように見えます (ORDER BY ステートメントはありません)。レコードのサブセットを探しているときに、NHibernate がこれを自動的に追加するのはなぜですか? 前もって感謝します
以下の SQL ステートメントを参照してください。
予期しない ORDER BY
exec sp_executesql N' SELECT TOP 2 Person1_36_0_, LastReco2_36_0_, SSN3_36_0_, FirstName4_36_0_、LastName5_36_0_、MiddleIn6_36_0_、Title7_36_0_、Suffix8_36_0_、 DateOfBi9_36_0_, IsDeceased10_36_0_, Decease11_36_0_, Contact12_36_0_, MailHol13_36_0_, MailHol14_36_0_、MailHol15_36_0_、Preferr16_36_0_、CreatedBy17_36_0_、Created18_36_0_、 ModifiedBy19_36_0_、Modify20_36_0_ FROM (SELECT ROW_NUMBER() OVER(ORDER BY __hibernate_sort_expr_0__) を行として、 query.Person1_36_0_、query.LastReco2_36_0_、query.SSN3_36_0_、query.FirstName4_36_0_、 query.LastName5_36_0_、query.MiddleIn6_36_0_、query.Title7_36_0_、query.Suffix8_36_0_、 query.DateOfBi9_36_0_、query.IsDeceased10_36_0_、query.Decease11_36_0_、 query.Contact12_36_0_、query.MailHol13_36_0_、query.MailHol14_36_0_、query.MailHol15_36_0_、 query.Preferr16_36_0_、query.CreatedBy17_36_0_、query.Created18_36_0_、 query.ModifiedBy19_36_0_、query.Modify20_36_0_、query.__hibernate_sort_expr_0__ から (this_.Person_id を Person1_36_0_ として選択し、this_.[LastRecordVersion] を LastReco2_36_0_ として選択し、 this_.[SSN] は SSN3_36_0_ として、this_.[名] は FirstName4_36_0_ として、this_.[姓] としては LastName5_36_0_、this_.[MiddleInitial] as MiddleIn6_36_0_、this_.[タイトル] as Title7_36_0_、 this_.[Suffix] as Suffix8_36_0_, this_.[DateOfBirth] as DateOfBi9_36_0_, this_.[IsDeceased] IsDeceased10_36_0_ として、this_.[DeceasedDate] として Decease11_36_0_、this_.[ContactMethod_id] として Contact12_36_0_、this_.[MailHoldReason_id] as MailHol13_36_0_、this_.[MailHoldStartDate] as MailHol14_36_0_、this_.[MailHoldEndDate] as MailHol15_36_0_、this_.[PreferredName] as Preferr16_36_0_、this_.[CreatedBy] as CreatedBy17_36_0_、this_.[CreatedDate] as Created18_36_0_、this_.[ModifiedBy] として ModifiedBy19_36_0_、this_.[ModifiedDate] として Modifie20_36_0_、CURRENT_TIMESTAMP を __hibernate_sort_expr_0__ として変更 FROM MC_Person this_ WHERE this_.[SSN] = @p0) query) ページ WHERE **page.row > 0 ORDER BY __hibernate_sort_expr_0__**', N'@p0 nvarchar(9)',@p0=N'123456789'
正しい SQL (上位 2 レコードを取得せずに)
exec sp_executesql N'SELECT this_.Person_id を Person1_36_0_ として、this_.[LastRecordVersion] を LastReco2_36_0_ として、 this_.[SSN] は SSN3_36_0_ として、this_.[名] は FirstName4_36_0_ として、this_.[姓] としては LastName5_36_0_、this_.[MiddleInitial] as MiddleIn6_36_0_、this_.[タイトル] as Title7_36_0_、 this_.[Suffix] as Suffix8_36_0_, this_.[DateOfBirth] as DateOfBi9_36_0_, this_.[IsDeceased] IsDeceased10_36_0_ として、this_.[DeceasedDate] として Decease11_36_0_、this_.[ContactMethod_id] として Contact12_36_0_、this_.[MailHoldReason_id] as MailHol13_36_0_、this_.[MailHoldStartDate] as MailHol14_36_0_、this_.[MailHoldEndDate] as MailHol15_36_0_、this_.[PreferredName] as Preferr16_36_0_、this_.[CreatedBy] as CreatedBy17_36_0_、this_.[CreatedDate] as Created18_36_0_、this_.[ModifiedBy] として ModifiedBy19_36_0_、this_.[ModifiedDate] として Modify20_36_0_ FROM MC_Person this_ WHERE this_.[SSN] = @p0', N'@p0 nvarchar(9)',@p0=N'123456789'