0

在工作中处理项目时发现了这个问题,但已设法使用 Breeze 的 DocCode 示例复制它。我正在使用最新的 1.3.0。基本上,当使用“expand”、“orderby”和“take”时,查询会返回错误的记录。该问题可以通过 queryTests.js 中的“按相关类别降序排序的产品”测试来证明:

测试中的查询是:

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

这会导致向 SQL Server 发出以下 SQL:

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 是按 ProductID 而不是 CategoryName 排序的,这会导致返回错误的记录。

那么这是一个错误还是我做错了什么?

4

1 回答 1

0

编辑:从 v 1.3.2 开始,这应该是固定的。如果您仍然看到问题,请返回此处。


好的,我刚刚复制了它,这是一个错误。感谢您找到并报告它。我会尝试在下一个版本中修复。当它进入时,我会回到这里。

于 2013-04-26T18:21:06.610 回答