SQLServer2005またはSQLServer2008に対して実行したときに、SubSonic 2.2 SubSonic.SqlQueryオブジェクトが同じC#コードに対して非常に異なるSQLを生成する理由を誰かが知っていますか?
SubSonic 2.2 / SQL Server 2005でしばらく実行されているサイトがあります。DBをmssql2008にアップグレードしたところ、次のエラーが発生しました。
SqlException(0x80131904):キーワード「AND」の近くの構文が正しくありません
失敗した時点でSqlQuery.ToString()をダンプしましたが、SQLServer2005とSQLServer2008でまったく同じコードベースを実行する場合の次の違いに気づきました。ソースコードは次のとおりです。
SubSonic.SqlQuery q = new Select()
.From(Views.VwSearchIndexQuery2Mtx)
.Paged(pageNumber, maximumRows)
.Where(VwSearchIndexQuery2Mtx.Columns.SearchIndexQueryId)
.In(
new Select(SearchIndexQueryGroupMap.Columns.SearchIndexQueryId)
.From(Tables.SearchIndexQueryGroupMap)
.Where(SearchIndexQueryGroupMap.Columns.SearchIndexQueryGroupId)
.IsEqualTo(searchIndexQueryGroupId));
また、SQLServer2005用に自動生成されたSQLは次のとおりです。
SELECT * FROM
(SELECT ROW_NUMBER() OVER ( ORDER BY CreatedOn DESC ) AS Row
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchTerms]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[IndustryId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[IndustryName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[DaysMonitored]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Incidents]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Relevance]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[CreatedOn]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[CreatedBy]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[ModifiedOn]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[ModifiedBy]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Deleted]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryTypeId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryTypeName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[LastUpdatedTime]
FROM [dbo].[Vw_SearchIndexQuery2_Mtx]
WHERE [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
IN (SELECT [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryId]
FROM [dbo].[SearchIndexQueryGroup_Map]
WHERE [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryGroupId] = @SearchIndexQueryGroupId0 ) )
AS PagedResults WHERE Row >= 1 AND Row <= 20
SQL Server 2008用に自動生成されたSQL:
DECLARE @Page int
DECLARE @PageSize int
SET @Page = 1
SET @PageSize = 20
SET NOCOUNT ON
-- create a temp table to hold order ids
DECLARE @TempTable TABLE (IndexId int identity, _keyID Int)
-- insert the table ids and row numbers into the memory table
INSERT INTO @TempTable ( _keyID )
SELECT [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
FROM [dbo].[Vw_SearchIndexQuery2_Mtx]
WHERE [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
IN (SELECT [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryId]
FROM [dbo].[SearchIndexQueryGroup_Map]
WHERE [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryGroupId]
= @SearchIndexQueryGroupId0
)
/* it's at this next AND where the error is thrown */
AND [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
IN (SELECT [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryId]
FROM [dbo].[SearchIndexQueryGroup_Map]
AND [dbo].[SearchIndexQueryGroup_Map].[SearchIndexQueryGroupId]
= @SearchIndexQueryGroupId0
)
ORDER BY CreatedOn DESC
-- select only those rows belonging to the proper page
SELECT [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchTerms]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[IndustryId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[IndustryName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[DaysMonitored]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Incidents]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Relevance]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[CreatedOn]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[CreatedBy]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[ModifiedOn]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[ModifiedBy]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[Deleted]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryTypeId]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryTypeName]
, [dbo].[Vw_SearchIndexQuery2_Mtx].[LastUpdatedTime]
FROM [dbo].[Vw_SearchIndexQuery2_Mtx]
INNER JOIN @TempTable t ON [dbo].[Vw_SearchIndexQuery2_Mtx].[SearchIndexQueryId] = t._keyID
WHERE t.IndexId BETWEEN ((@Page - 1) * @PageSize + 1) AND (@Page * @PageSize)
エラーが発生している理由はわかっています。SQLは、上記でコメントしたANDによって無効になっています。SubSonicがSQLServer2008で動作した後、無効なSQLを生成している理由がわかりません。SQLServer2008の場合、一時テーブルを使用しており、WHERE...INサブを繰り返しているように見えます。クエリ。アップグレードされたDBが100に設定されていたので、おそらくISO互換性レベルだと思いました。90と80の両方に設定してテストしたところ、SubSonicはそれぞれの場合と同じSQLを生成します。(ところで、「select rownumber()over ...asrow」を使用するSQLServer2005用に生成されたコードは、SQL Server 2008に対して正常に実行されます。)
なぜこれが起こっているのか、そしてそれを追跡する方法について誰かが何か考えを持っていますか?
どうもありがとう、
テリー