0

仕事でプロジェクトに取り組んでいるときにこの問題を発見しましたが、Breeze の DocCode サンプルを使用して再現することができました。最新の 1.3.0 を使用しています。基本的に、「expand」、「orderby」、および「take」を使用すると、クエリによって間違ったレコードが返されます。この問題は、queryTests.js の「関連するカテゴリの降順で並べ替えられた製品」テストで実証できます。

テストのクエリは次のとおりです。

    var query = EntityQuery.from("Products")
        .expand("Category")
        .orderBy("Category.CategoryName desc, ProductName");

これにより、次の SQL が SQL Server に発行されます。

SELECT 
[Extent1].[ProductID] AS [ProductID], 
[Extent1].[ProductName] AS [ProductName], 
[Extent1].[SupplierID] AS [SupplierID], 
[Extent1].[CategoryID] AS [CategoryID], 
[Extent1].[QuantityPerUnit] AS [QuantityPerUnit], 
[Extent1].[UnitPrice] AS [UnitPrice], 
[Extent1].[UnitsInStock] AS [UnitsInStock], 
[Extent1].[UnitsOnOrder] AS [UnitsOnOrder], 
[Extent1].[ReorderLevel] AS [ReorderLevel], 
[Extent1].[Discontinued] AS [Discontinued], 
[Extent2].[CategoryID] AS [CategoryID1], 
[Extent2].[CategoryName] AS [CategoryName], 
[Extent2].[Description] AS [Description], 
[Extent2].[Picture] AS [Picture]
FROM  [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN [dbo].[Categories] AS [Extent2] ON [Extent1].[CategoryID] = [Extent2].[CategoryID]
ORDER BY [Extent2].[CategoryName] DESC, [Extent1].[ProductName] ASC

これは問題なく、CategoryName でソートされた正しい結果が得られます。ただし、クエリを次のように変更すると:

    var query = EntityQuery.from("Products")
        .expand("Category")
        .orderBy("Category.CategoryName desc, ProductName").take(10);

「.take(10)」を追加しました。SQL は次のようになります。

exec sp_executesql N'SELECT 
[Limit1].[ProductID] AS [ProductID], 
[Limit1].[ProductName] AS [ProductName], 
[Limit1].[SupplierID] AS [SupplierID], 
[Limit1].[CategoryID1] AS [CategoryID], 
[Limit1].[QuantityPerUnit] AS [QuantityPerUnit], 
[Limit1].[UnitPrice] AS [UnitPrice], 
[Limit1].[UnitsInStock] AS [UnitsInStock], 
[Limit1].[UnitsOnOrder] AS [UnitsOnOrder], 
[Limit1].[ReorderLevel] AS [ReorderLevel], 
[Limit1].[Discontinued] AS [Discontinued], 
[Extent3].[CategoryID] AS [CategoryID1], 
[Extent3].[CategoryName] AS [CategoryName], 
[Extent3].[Description] AS [Description], 
[Extent3].[Picture] AS [Picture]
FROM   (SELECT TOP (@p__linq__0) [Extent1].[ProductID] AS [ProductID], [Extent1].[ProductName] AS [ProductName]\, [Extent1].[SupplierID] AS [SupplierID], [Extent1].[CategoryID] AS [CategoryID1], [Extent1].[QuantityPerUnit] AS [QuantityPerUnit], [Extent1].[UnitPrice] AS [UnitPrice], [Extent1].[UnitsInStock] AS [UnitsInStock], [Extent1].[UnitsOnOrder] AS [UnitsOnOrder], [Extent1].[ReorderLevel] AS [ReorderLevel], [Extent1].[Discontinued] AS [Discontinued], [Extent2].[CategoryName] AS [CategoryName]
    FROM  [dbo].[Products] AS [Extent1]
    LEFT OUTER JOIN [dbo].[Categories] AS [Extent2] ON [Extent1].[CategoryID] = [Extent2].[CategoryID]
    ORDER BY [Extent1].[ProductID] ASC ) AS [Limit1]
LEFT OUTER JOIN [dbo].[Categories] AS [Extent3] ON [Limit1].[CategoryID1] = [Extent3].[CategoryID]
ORDER BY [Limit1].[CategoryName] DESC, [Limit1].[ProductName] ASC',N'@p__linq__0 int',@p__linq__0=10

Extent1 が CategoryName ではなく ProductID によって順序付けられているため、間違ったレコードが返されるため、これは間違っています。

これはバグですか、それとも何か間違っていますか?

4

1 に答える 1